Commit 36400a0c authored by Daniel Kornhauser's avatar Daniel Kornhauser

Adding Camera Module

parent 5aff563a
......@@ -6,10 +6,11 @@
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-2.4" />
<option name="gradleJvm" value="1.7" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/CameraModule" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/openCVLibrary2411" />
</set>
......
......@@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -2,6 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/CameraModule/CameraModule.iml" filepath="$PROJECT_DIR$/CameraModule/CameraModule.iml" />
<module fileurl="file://$PROJECT_DIR$/EarRecognition.iml" filepath="$PROJECT_DIR$/EarRecognition.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/openCVLibrary2411/openCVLibrary2411.iml" filepath="$PROJECT_DIR$/openCVLibrary2411/openCVLibrary2411.iml" />
......
# svn
*.svn*
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated GUI files
*/R.java
# generated folder
bin
gen
# local
local.properties
proguard.cfg
# log files
log*.txt
# archives
*.gz
*.tar
*.zip
# eclipse
*.metadata
*.settings
#idea
*.idea
*.iml
out/
#gradle
/build
.gradle/
\ No newline at end of file
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.edmodo:cropper:1.0.1'
compile 'com.squareup.picasso:picasso:2.2.0'
compile 'com.jakewharton.timber:timber:2.2.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:/androidsdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
\ No newline at end of file
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yalantis.cameramodule">
<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"/>
<uses-feature android:name="android.hardware.camera" android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<application>
<activity
android:name="com.yalantis.cameramodule.activity.CameraActivity"
android:theme="@style/Theme.TranslucentNavigationBar"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait"/>
<activity
android:name="com.yalantis.cameramodule.activity.PhotoCropActivity"
android:label="@string/lbl_photo_crop"
android:screenOrientation="portrait"/>
<activity
android:name="com.yalantis.cameramodule.activity.PhotoPreviewActivity"
android:label="@string/lbl_photo_preview"
android:screenOrientation="portrait"/>
</application>
</manifest>
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.squareup.picasso;
public class PicassoTools {
public static void clearCache(Picasso p) {
p.cache.clear();
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule;
public final class CameraConst {
public static final boolean DEBUG = true;
public static final int COMPRESS_QUALITY = 90;
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule;
import android.content.Context;
import com.yalantis.cameramodule.interfaces.Initializer;
import com.yalantis.cameramodule.manager.ImageManager;
import com.yalantis.cameramodule.manager.LoggerManager;
import com.yalantis.cameramodule.manager.SharedPrefManager;
public enum ManagerInitializer implements Initializer {
i;
@Override
public void init(Context context) {
SharedPrefManager.i.init(context);
LoggerManager.i.init(context);
ImageManager.i.init(context);
}
@Override
public void clear() {
SharedPrefManager.i.clear();
LoggerManager.i.clear();
ImageManager.i.clear();
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.activity;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
public abstract class BaseActivity extends Activity {
protected Handler handler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
return BaseActivity.this.handleMessage(msg);
}
});
}
protected void hideKeyboard() {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
View view = this.getCurrentFocus();
if (view != null) {
if (inputManager != null) {
inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
protected boolean handleMessage(Message msg) {
return false;
}
protected void showActionBar() {
if (getActionBar() != null) {
getActionBar().show();
}
}
protected void hideActionBar() {
if (getActionBar() != null) {
getActionBar().hide();
}
}
public void showBack() {
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
public void hideBack() {
getActionBar().setDisplayShowHomeEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case android.R.id.home:
super.onBackPressed();
return true;
}
return super.onOptionsItemSelected(menuItem);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.activity;
import android.app.Fragment;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.manager.ImageManager;
public abstract class BasePhotoActivity extends BaseActivity {
protected String path;
protected String name;
protected Bitmap bitmap;
protected View progressBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showActionBar();
showBack();
setContentView(R.layout.activity_photo);
if (getIntent().hasExtra(EXTRAS.PATH)) {
path = getIntent().getStringExtra(EXTRAS.PATH);
} else {
throw new RuntimeException("There is no path to image in extras");
}
if (getIntent().hasExtra(EXTRAS.NAME)) {
name = getIntent().getStringExtra(EXTRAS.NAME);
} else {
throw new RuntimeException("There is no image name in extras");
}
progressBar = findViewById(R.id.progress);
}
@Override
protected void onResume() {
super.onResume();
if (bitmap == null || bitmap.isRecycled()) {
loadPhoto();
}
}
protected abstract void showPhoto(Bitmap bitmap);
protected void rotatePhoto(float angle) {
synchronized (bitmap) {
bitmap = ImageManager.i.rotatePhoto(path, angle);
showPhoto(bitmap);
}
setResult(EXTRAS.RESULT_EDITED, setIntentData());
}
protected void deletePhoto() {
setResult(EXTRAS.RESULT_DELETED, setIntentData());
finish();
}
protected void loadPhoto() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
ImageManager.i.loadPhoto(path, metrics.widthPixels, metrics.heightPixels, loadingTarget);
}
protected void setFragment(Fragment fragment) {
getFragmentManager()
.beginTransaction()
.replace(R.id.fragment_content, fragment)
.commit();
}
private Target loadingTarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
progressBar.setVisibility(View.GONE);
BasePhotoActivity.this.bitmap = bitmap;
showPhoto(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
progressBar.setVisibility(View.GONE);
bitmap = null;
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
progressBar.setVisibility(View.VISIBLE);
}
};
protected Intent setIntentData() {
return setIntentData(null);
}
protected Intent setIntentData(Intent intent) {
if (intent == null) {
intent = new Intent();
}
intent.putExtra(EXTRAS.PATH, path);
intent.putExtra(EXTRAS.NAME, name);
return intent;
}
public static final class EXTRAS {
public static final String PATH = "path";
public static final String NAME = "name";
public static final String FROM_CAMERA = "from_camera";
public static final int REQUEST_PHOTO_EDIT = 7338;
public static final int RESULT_EDITED = 338;
public static final int RESULT_DELETED = 3583;
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.activity;
import android.content.Intent;
import android.media.ExifInterface;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.widget.Toast;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.fragment.CameraFragment;
import com.yalantis.cameramodule.interfaces.*;
import com.yalantis.cameramodule.manager.SharedPrefManager;
import com.yalantis.cameramodule.util.PhotoUtil;
import com.yalantis.cameramodule.util.SavingPhotoTask;
import timber.log.Timber;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CameraActivity extends BaseActivity implements PhotoTakenCallback, PhotoSavedListener, RawPhotoTakenCallback,
CameraParamsChangedListener {
public static final String PATH = "path";
public static final String USE_FRONT_CAMERA = "use_front_camera";
public static final String OPEN_PHOTO_PREVIEW = "open_photo_preview";
public static final String LAYOUT_ID = "layout_id";
private static final String IMG_PREFIX = "IMG_";
private static final String IMG_POSTFIX = ".jpg";
private static final String TIME_FORMAT = "yyyyMMdd_HHmmss";
private KeyEventsListener keyEventsListener;
private PhotoSavedListener photoSavedListener;
private String path;
private boolean openPreview;
private boolean saving;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hideActionBar();
setContentView(R.layout.activity_with_fragment);
if (TextUtils.isEmpty(path = getIntent().getStringExtra(PATH))) {
path = Environment.getExternalStorageDirectory().getPath();
}
openPreview = getIntent().getBooleanExtra(OPEN_PHOTO_PREVIEW, SharedPrefManager.i.isOpenPhotoPreview());
if (openPreview != SharedPrefManager.i.isOpenPhotoPreview()) {
SharedPrefManager.i.setOpenPhotoPreview(openPreview);
}
boolean useFrontCamera = getIntent().getBooleanExtra(USE_FRONT_CAMERA, SharedPrefManager.i.useFrontCamera());
if (useFrontCamera != SharedPrefManager.i.useFrontCamera()) {
SharedPrefManager.i.setUseFrontCamera(useFrontCamera);
}
init();
}
private void init() {
CameraFragment fragment;
int layoutId = getIntent().getIntExtra(LAYOUT_ID, -1);
if (layoutId > 0) {
fragment = CameraFragment.newInstance(layoutId, this, createCameraParams());
} else {
fragment = CameraFragment.newInstance(this, createCameraParams());
}
fragment.setParamsChangedListener(this);
keyEventsListener = fragment;
photoSavedListener = fragment;
getFragmentManager()
.beginTransaction()
.replace(R.id.fragment_content, fragment)
.commit();
}
private Bundle createCameraParams() {
Bundle bundle = new Bundle();
bundle.putInt(CameraFragment.RATIO, SharedPrefManager.i.getCameraRatio());
bundle.putInt(CameraFragment.FLASH_MODE, SharedPrefManager.i.getCameraFlashMode());
bundle.putInt(CameraFragment.HDR_MODE, SharedPrefManager.i.isHDR());
bundle.putInt(CameraFragment.QUALITY, SharedPrefManager.i.getCameraQuality());
bundle.putInt(CameraFragment.FOCUS_MODE, SharedPrefManager.i.getCameraFocusMode());
bundle.putBoolean(CameraFragment.FRONT_CAMERA, SharedPrefManager.i.useFrontCamera());
return bundle;
}
private String createName() {
String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date());
return IMG_PREFIX + timeStamp + IMG_POSTFIX;
}
@Override
public void photoTaken(byte[] data, int orientation) {
savePhoto(data, createName(), path, orientation);
}
@Override
public void rawPhotoTaken(byte[] data) {
Timber.d("rawPhotoTaken: data[%1d]", data.length);
}
private void savePhoto(byte[] data, String name, String path, int orientation) {
saving = true;
new SavingPhotoTask(data, name, path, orientation, this).execute();
}
@Override
public void photoSaved(String path, String name) {
saving = false;
Toast.makeText(this, "Photo " + name + " saved", Toast.LENGTH_SHORT).show();
Timber.d("Photo " + name + " saved");
if (CameraConst.DEBUG) {
printExifOrientation(path);
}
if (openPreview) {
openPreview(path, name);
}
if (photoSavedListener != null) {
photoSavedListener.photoSaved(path, name);
}
}
private void openPreview(String path, String name) {
Intent intent = new Intent(this, PhotoPreviewActivity.class);
intent.putExtra(BasePhotoActivity.EXTRAS.PATH, path);
intent.putExtra(BasePhotoActivity.EXTRAS.NAME, name);
intent.putExtra(BasePhotoActivity.EXTRAS.FROM_CAMERA, true);
startActivityForResult(intent, BasePhotoActivity.EXTRAS.REQUEST_PHOTO_EDIT);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == BasePhotoActivity.EXTRAS.REQUEST_PHOTO_EDIT) {
switch (resultCode) {
case BasePhotoActivity.EXTRAS.RESULT_DELETED:
String path = data.getStringExtra(BasePhotoActivity.EXTRAS.PATH);
PhotoUtil.deletePhoto(path);
break;
}
}
}
private void printExifOrientation(String path) {
try {
ExifInterface exif = new ExifInterface(path);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
Timber.d("Orientation: " + orientation);
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
keyEventsListener.zoomIn();
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
keyEventsListener.zoomOut();
return true;
case KeyEvent.KEYCODE_BACK:
onBackPressed();
return true;
case KeyEvent.KEYCODE_CAMERA:
keyEventsListener.takePhoto();
return true;
}
return false;
}
@Override
public void onQualityChanged(int id) {
SharedPrefManager.i.setCameraQuality(id);
}
@Override
public void onRatioChanged(int id) {
SharedPrefManager.i.setCameraRatio(id);
}
@Override
public void onFlashModeChanged(int id) {
SharedPrefManager.i.setCameraFlashMode(id);
}
@Override
public void onHDRChanged(int id) {
SharedPrefManager.i.setHDRMode(id);
}
@Override
public void onFocusModeChanged(int id) {
SharedPrefManager.i.setCameraFocusMode(id);
}
@Override
public void onBackPressed() {
if (!saving) {
super.onBackPressed();
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.activity;
import android.graphics.Bitmap;
import android.graphics.RectF;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.fragment.PhotoCropFragment;
import com.yalantis.cameramodule.interfaces.PhotoCroppedCallback;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
import com.yalantis.cameramodule.manager.ImageManager;
public class PhotoCropActivity extends BasePhotoActivity implements PhotoCroppedCallback {
private PhotoCropFragment cropFragment;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.photo_crop_options, menu);
return super.onCreateOptionsMenu(menu);
}
public void apply(MenuItem ite) {
cropFragment.applyCrop();
}
public void cancel(MenuItem ite) {
finish();
}
@Override
protected void showPhoto(Bitmap bitmap) {
if (cropFragment == null) {
cropFragment = PhotoCropFragment.newInstance(bitmap);
setFragment(cropFragment);
} else {
cropFragment.setBitmap(bitmap);
}
}
@Override
public void onPhotoCropped(int width, int height, Bitmap croppedBitmap, RectF cropRect) {
ImageManager.i.cropBitmap(path, width, height, croppedBitmap, cropRect, new PhotoSavedListener() {
@Override
public void photoSaved(String path, String name) {
setResult(EXTRAS.RESULT_EDITED, setIntentData());
finish();
}
});
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.fragment.PhotoPreviewFragment;
public class PhotoPreviewActivity extends BasePhotoActivity {
private PhotoPreviewFragment previewFragment;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent().getBooleanExtra(EXTRAS.FROM_CAMERA, false)) {
setTitle(R.string.lbl_take_another);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.photo_preview_options, menu);
return super.onCreateOptionsMenu(menu);
}
public void deletePhoto(MenuItem item) {
deletePhoto();
}
public void rotateLeft(MenuItem item) {
rotatePhoto(-90);
}
public void rotateRight(MenuItem item) {
rotatePhoto(90);
}
public void openPhotoCropper(MenuItem item) {
Intent intent = new Intent(this, PhotoCropActivity.class);
startActivityForResult(setIntentData(intent), EXTRAS.REQUEST_PHOTO_EDIT);
}
@Override
protected void showPhoto(Bitmap bitmap) {
if (previewFragment == null) {
previewFragment = PhotoPreviewFragment.newInstance(bitmap);
setFragment(previewFragment);
} else {
previewFragment.setBitmap(bitmap);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == EXTRAS.REQUEST_PHOTO_EDIT) {
if (resultCode == EXTRAS.RESULT_EDITED) {
setResult(EXTRAS.RESULT_EDITED, setIntentData());
loadPhoto();
}
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.adapters;
import java.util.List;
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.BaseAdapter;
public abstract class BaseListAdapter<T> extends BaseAdapter {
private Context mContext;
private List<T> mList;
private int mLayoutId;
public BaseListAdapter(Context context, List<T> list, int layout) {
mContext = context;
setList(list);
mLayoutId = layout;
}
@Override
public int getCount() {
if (mList != null) {
return mList.size();
}
return 0;
}
public void addItems(List<T> items) {
mList.addAll(items);
notifyDataSetChanged();
}
public void addItem(T type) {
mList.add(type);
notifyDataSetChanged();
}
@Override
public T getItem(int position) {
return position >= 0 && position < mList.size() ? mList.get(position) : null;
}
@Override
public long getItemId(int position) {
return position;
}
public Context getContext() {
return mContext;
}
public Resources getResources() {
return getContext().getResources();
}
public List<T> getList() {
return mList;
}
public void setList(List<T> list) {
this.mList = list;
}
public void removeItem(int position) {
mList.remove(position);
notifyDataSetChanged();
}
public View getLayout() {
return getInflater().inflate(getLayoutId(), null);
}
public int getLayoutId() {
return mLayoutId;
}
public LayoutInflater getInflater() {
return LayoutInflater.from(mContext);
}
public void clear() {
mList.clear();
notifyDataSetChanged();
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.adapters;
import java.util.List;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.yalantis.cameramodule.R;
public class ObjectToStringAdapter<T> extends BaseListAdapter<T> {
public ObjectToStringAdapter(Context context, List<T> list) {
super(context, list, R.layout.object_to_string_list_item);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return createView(position, convertView, false);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return createView(position, convertView, true);
}
private View createView(int position, View convertView, boolean dropDown) {
ViewHolder holder;
if (convertView == null) {
if (dropDown) {
convertView = getDropDownLayout();
} else {
convertView = getLayout();
}
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
T item = getItem(position);
if (item != null) {
holder.text.setText(item.toString());
}
return convertView;
}
public View getDropDownLayout() {
return getInflater().inflate(R.layout.object_to_string_dropdown_list_item, null);
}
class ViewHolder {
TextView text;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.control;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.RectF;
import android.hardware.Camera;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;
import com.yalantis.cameramodule.interfaces.FocusCallback;
import com.yalantis.cameramodule.interfaces.KeyEventsListener;
import com.yalantis.cameramodule.model.FocusMode;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import timber.log.Timber;
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback, Camera.AutoFocusCallback {
private static final int DISPLAY_ORIENTATION = 90;
private static final float FOCUS_AREA_SIZE = 75f;
private static final float STROKE_WIDTH = 5f;
private static final float FOCUS_AREA_FULL_SIZE = 2000f;
private static final int ACCURACY = 3;
private Activity activity;
private Camera camera;
private ImageView canvasFrame;
private Canvas canvas;
private Paint paint;
private FocusMode focusMode = FocusMode.AUTO;
private ImageView canvasFrame2;
private Canvas canvas2;
private Paint paint2;
private boolean hasAutoFocus;
private boolean focusing;
private boolean focused;
private float focusKoefW;
private float focusKoefH;
private float prevScaleFactor;
private FocusCallback focusCallback;
private Rect tapArea;
private KeyEventsListener keyEventsListener;
public CameraPreview(Activity activity, Camera camera, ImageView canvasFrame, FocusCallback focusCallback, KeyEventsListener keyEventsListener) {
super(activity);
this.activity = activity;
this.camera = camera;
this.canvasFrame = canvasFrame;
this.focusCallback = focusCallback;
this.keyEventsListener = keyEventsListener;
List<String> supportedFocusModes = camera.getParameters().getSupportedFocusModes();
hasAutoFocus = supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO);
initHolder();
}
private void initHolder() {
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
SurfaceHolder holder = getHolder();
if (holder != null) {
holder.addCallback(this);
holder.setKeepScreenOn(true);
}
}
private void initFocusDrawingTools(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
canvas = new Canvas(bitmap);
paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStrokeWidth(STROKE_WIDTH);
canvasFrame.setImageBitmap(bitmap);
}
private void initEarDrawingTools(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
canvas2 = new Canvas(bitmap);
paint2 = new Paint();
paint2.setAntiAlias(true);
paint2.setColor(Color.BLUE);
paint2.setStrokeWidth(1f);
canvasFrame.setImageBitmap(bitmap);
}
public void surfaceCreated(SurfaceHolder holder) {
Timber.d("surfaceCreated");
// The Surface has been created, now tell the camera where to draw the preview.
startPreview(holder);
}
public void surfaceDestroyed(SurfaceHolder holder) {
Timber.d("surfaceDestroyed");
stopPreview();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Timber.d("surfaceChanged(%1d, %2d)", width, height);
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
initFocusDrawingTools(width, height);
initFocusKoefs(width, height);
if (holder.getSurface() == null) {
// preview surface does not exist
return;
}
stopPreview();
startPreview(holder);
setOnTouchListener(new CameraTouchListener());
}
private void initFocusKoefs(float width, float height) {
focusKoefW = width / FOCUS_AREA_FULL_SIZE;
focusKoefH = height / FOCUS_AREA_FULL_SIZE;
}
public void setFocusMode(FocusMode focusMode) {
clearCameraFocus();
this.focusMode = focusMode;
focusing = false;
setOnTouchListener(new CameraTouchListener());
}
private void startFocusing() {
if (!focusing) {
focused = false;
focusing = true;
if (focusMode == FocusMode.AUTO || (focusMode == FocusMode.TOUCH && tapArea == null)) {
drawFocusFrame(createAutoFocusRect());
}
camera.autoFocus(this);
}
}
public void takePicture() {
if (hasAutoFocus) {
if (focusMode == FocusMode.AUTO) {
startFocusing();
}
if (focusMode == FocusMode.TOUCH) {
if (focused && tapArea != null) {
focused();
} else {
startFocusing();
}
}
} else {
focused();
}
}
private Rect createAutoFocusRect() {
int left = (int) (getWidth() / 2 - FOCUS_AREA_SIZE);
int right = (int) (getWidth() / 2 + FOCUS_AREA_SIZE);
int top = (int) (getHeight() / 2 - FOCUS_AREA_SIZE);
int bottom = (int) (getHeight() / 2 + FOCUS_AREA_SIZE);
return new Rect(left, top, right, bottom);
}
private void startPreview(SurfaceHolder holder) {
Timber.d("startPreview");
try {
camera.setPreviewDisplay(holder);
camera.setDisplayOrientation(DISPLAY_ORIENTATION);
Camera.Parameters parameters = camera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
camera.setParameters(parameters);
initEarDrawingTools(canvas.getWidth(),canvas.getHeight());
drawEarFrame(new Rect(0, 30, 50, 50));
camera.startPreview();
} catch (Exception e) {
Timber.e(e, "Error starting camera preview: " + e.getMessage());
}
}
private void stopPreview() {
Timber.d("stopPreview");
try {
camera.stopPreview();
} catch (Exception e) {
Timber.e(e, "Error stopping camera preview: " + e.getMessage());
}
}
private void drawFocusFrame(Rect rect) {
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawLine(rect.left, rect.top, rect.right, rect.top, paint);
canvas.drawLine(rect.right, rect.top, rect.right, rect.bottom, paint);
canvas.drawLine(rect.right, rect.bottom, rect.left, rect.bottom, paint);
canvas.drawLine(rect.left, rect.bottom, rect.left, rect.top, paint);
canvasFrame.draw(canvas);
canvasFrame.invalidate();
}
private void drawEarFrame(Rect rect) {
canvas2.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
paint2.setStyle(Paint.Style.STROKE);
float cx = canvas2.getWidth() * 0.5f;
float cy = canvas2.getHeight() * 0.5f;
float delta = canvas2.getWidth()*0.25f;
RectF rectf = new RectF(cx-delta, cy -delta, cx+delta, cy+delta);
canvas2.drawArc(rectf, 90, -180, true, paint2);
//canvas2.drawCircle(canvas2.getWidth() / 2, canvas2.getHeight() / 2, canvas2.getWidth() / 4, paint2);
//canvas2.drawCircle(canvas2.getWidth()/2, canvas2.getHeight()/2, 10, paint2);
//canvas2.drawLine(rect.left, rect.top, rect.right, rect.top, paint2);
//canvas2.drawLine(rect.right, rect.top, rect.right, rect.bottom, paint2);
//canvas2.drawLine(rect.right, rect.bottom, rect.left, rect.bottom, paint2);
//canvas2.drawLine(rect.left, rect.bottom, rect.left, rect.top, paint2);
canvasFrame.draw(canvas2);
canvasFrame.invalidate();
}
private void clearCameraFocus() {
if (hasAutoFocus) {
focused = false;
camera.cancelAutoFocus();
if (canvas != null) {
tapArea = null;
try {
Camera.Parameters parameters = camera.getParameters();
parameters.setFocusAreas(null);
parameters.setMeteringAreas(null);
camera.setParameters(parameters);
} catch (Exception e) {
Timber.e(e, "clearCameraFocus");
} finally {
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvasFrame.draw(canvas);
canvasFrame.invalidate();
}
}
}
}
@Override
public void onAutoFocus(boolean success, Camera camera) {
focusing = false;
focused = true;
if (focusMode == FocusMode.AUTO) {
focused();
}
if (focusMode == FocusMode.TOUCH && tapArea == null) {
focused();
}
}
private void focused() {
focusing = false;
if (focusCallback != null) {
focusCallback.onFocused(camera);
}
}
public void onPictureTaken() {
clearCameraFocus();
}
protected void focusOnTouch(MotionEvent event) {
tapArea = calculateTapArea(event.getX(), event.getY(), 1f);
Camera.Parameters parameters = camera.getParameters();
int maxFocusAreas = parameters.getMaxNumFocusAreas();
if (maxFocusAreas > 0) {
Camera.Area area = new Camera.Area(convert(tapArea), 100);
parameters.setFocusAreas(Arrays.asList(area));
}
maxFocusAreas = parameters.getMaxNumMeteringAreas();
if (maxFocusAreas > 0) {
Rect rectMetering = calculateTapArea(event.getX(), event.getY(), 1.5f);
Camera.Area area = new Camera.Area(convert(rectMetering), 100);
parameters.setMeteringAreas(Arrays.asList(area));
}
camera.setParameters(parameters);
drawFocusFrame(tapArea);
startFocusing();
}
/**
* Convert touch position x:y to {@link android.hardware.Camera.Area} position -1000:-1000 to 1000:1000.
*/
private Rect calculateTapArea(float x, float y, float coefficient) {
int areaSize = Float.valueOf(FOCUS_AREA_SIZE * coefficient).intValue();
int left = clamp((int) x - areaSize / 2, 0, getWidth() - areaSize);
int top = clamp((int) y - areaSize / 2, 0, getHeight() - areaSize);
RectF rect = new RectF(left, top, left + areaSize, top + areaSize);
Timber.d("tap: " + rect.toShortString());
return round(rect);
}
private Rect round(RectF rect) {
return new Rect(Math.round(rect.left), Math.round(rect.top), Math.round(rect.right), Math.round(rect.bottom));
}
private Rect convert(Rect rect) {
Rect result = new Rect();
result.top = normalize(rect.top / focusKoefH - 1000);
result.left = normalize(rect.left / focusKoefW - 1000);
result.right = normalize(rect.right / focusKoefW - 1000);
result.bottom = normalize(rect.bottom / focusKoefH - 1000);
Timber.d("convert: " + result.toShortString());
return result;
}
private int normalize(float value) {
if (value > 1000) {
return 1000;
}
if (value < -1000) {
return -1000;
}
return Math.round(value);
}
private int clamp(int x, int min, int max) {
if (x > max) {
return max;
}
if (x < min) {
return min;
}
return x;
}
private void scale(float scaleFactor) {
scaleFactor = BigDecimal.valueOf(scaleFactor).setScale(ACCURACY, BigDecimal.ROUND_HALF_UP).floatValue();
if (Float.compare(scaleFactor, 1.0f) == 0 || Float.compare(scaleFactor, prevScaleFactor) == 0) {
return;
}
if (scaleFactor > 1f) {
keyEventsListener.zoomIn();
}
if (scaleFactor < 1f) {
keyEventsListener.zoomOut();
}
prevScaleFactor = scaleFactor;
}
private class CameraTouchListener implements OnTouchListener {
private ScaleGestureDetector mScaleDetector = new ScaleGestureDetector(activity, new ScaleListener());
private GestureDetector mTapDetector = new GestureDetector(activity, new TapListener());
@Override
public boolean onTouch(View v, MotionEvent event) {
clearCameraFocus();
if (event.getPointerCount() > 1) {
mScaleDetector.onTouchEvent(event);
return true;
}
if (hasAutoFocus && focusMode == FocusMode.TOUCH) {
mTapDetector.onTouchEvent(event);
return true;
}
return true;
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
scale(detector.getScaleFactor());
return true;
}
}
private class TapListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
focusOnTouch(event);
return true;
}
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.control;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.widget.ImageView;
public class PinchImageView extends PreviewImageView {
private Matrix matrix = new Matrix();
// We can be in one of these 3 states
private static final int NONE = 0;
private static final int DRAG = 1;
private static final int ZOOM = 2;
private int mode = NONE;
// Remember some things for zooming
private PointF last = new PointF();
private PointF start = new PointF();
private final float minScale = 1f;
private float maxScale = 3f;
private float[] m;
private float redundantXSpace, redundantYSpace;
private float width, height;
private static final int CLICK = 3;
private float saveScale = 1f;
private float right, bottom, origWidth, origHeight, bmWidth, bmHeight;
private ScaleGestureDetector mScaleDetector;
public PinchImageView(Context context) {
super(context);
sharedConstructing(context);
}
public PinchImageView(Context context, AttributeSet attrs) {
super(context, attrs);
sharedConstructing(context);
}
private void sharedConstructing(Context context) {
super.setClickable(true);
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
matrix.setTranslate(minScale, minScale);
m = new float[9];
setImageMatrix(matrix);
setScaleType(ImageView.ScaleType.MATRIX);
setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
mScaleDetector.onTouchEvent(event);
matrix.getValues(m);
float x = m[Matrix.MTRANS_X];
float y = m[Matrix.MTRANS_Y];
PointF curr = new PointF(event.getX(), event.getY());
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
last.set(event.getX(), event.getY());
start.set(last);
mode = DRAG;
break;
case MotionEvent.ACTION_MOVE:
if (mode == DRAG) {
float deltaX = curr.x - last.x;
float deltaY = curr.y - last.y;
float scaleWidth = Math.round(origWidth * saveScale);
float scaleHeight = Math.round(origHeight * saveScale);
if (scaleWidth < width) {
deltaX = 0;
if (y + deltaY > 0)
deltaY = -y;
else if (y + deltaY < -bottom)
deltaY = -(y + bottom);
} else if (scaleHeight < height) {
deltaY = 0;
if (x + deltaX > 0)
deltaX = -x;
else if (x + deltaX < -right)
deltaX = -(x + right);
} else {
if (x + deltaX > 0)
deltaX = -x;
else if (x + deltaX < -right)
deltaX = -(x + right);
if (y + deltaY > 0)
deltaY = -y;
else if (y + deltaY < -bottom)
deltaY = -(y + bottom);
}
matrix.postTranslate(deltaX, deltaY);
last.set(curr.x, curr.y);
}
break;
case MotionEvent.ACTION_UP:
mode = NONE;
int xDiff = (int) Math.abs(curr.x - start.x);
int yDiff = (int) Math.abs(curr.y - start.y);
if (xDiff < CLICK && yDiff < CLICK) {
performClick();
}
break;
case MotionEvent.ACTION_POINTER_UP:
mode = NONE;
break;
}
setImageMatrix(matrix);
invalidate();
// indicate event was handled
return true;
}
});
}
@Override
public void setImageBitmap(Bitmap bm) {
super.setImageBitmap(bm);
if (bm != null) {
bmWidth = bm.getWidth();
bmHeight = bm.getHeight();
}
}
@Override
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);
if (drawable == null) {
return;
}
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
bmWidth = bitmapDrawable.getBitmap().getWidth();
bmHeight = bitmapDrawable.getBitmap().getHeight();
}
} else {
int intrinsicHeight = drawable.getIntrinsicHeight();
int intrinsicWidth = drawable.getIntrinsicWidth();
bmHeight = intrinsicHeight > 0 ? intrinsicHeight : 0;
bmWidth = intrinsicWidth > 0 ? intrinsicWidth : 0;
}
}
public void setMaxZoom(float x) {
maxScale = x;
}
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
mode = ZOOM;
return true;
}
@Override
public boolean onScale(ScaleGestureDetector detector) {
scale(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
return true;
}
}
private void scale(float scaleFactor, float focusX, float focusY) {
float origScale = saveScale;
saveScale *= scaleFactor;
if (saveScale > maxScale) {
saveScale = maxScale;
scaleFactor = maxScale / origScale;
} else if (saveScale < minScale) {
saveScale = minScale;
scaleFactor = minScale / origScale;
}
right = width * saveScale - width - (2 * redundantXSpace * saveScale);
bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
if (origWidth * saveScale <= width || origHeight * saveScale <= height) {
matrix.postScale(scaleFactor, scaleFactor, width / 2, height / 2);
if (scaleFactor < 1) {
matrix.getValues(m);
float x = m[Matrix.MTRANS_X];
float y = m[Matrix.MTRANS_Y];
if (scaleFactor < 1) {
if (Math.round(origWidth * saveScale) < width) {
if (y < -bottom)
matrix.postTranslate(0, -(y + bottom));
else if (y > 0)
matrix.postTranslate(0, -y);
} else {
if (x < -right)
matrix.postTranslate(-(x + right), 0);
else if (x > 0)
matrix.postTranslate(-x, 0);
}
}
}
} else {
matrix.postScale(scaleFactor, scaleFactor, focusX, focusY);
matrix.getValues(m);
float x = m[Matrix.MTRANS_X];
float y = m[Matrix.MTRANS_Y];
if (scaleFactor < 1) {
if (x < -right)
matrix.postTranslate(-(x + right), 0);
else if (x > 0)
matrix.postTranslate(-x, 0);
if (y < -bottom)
matrix.postTranslate(0, -(y + bottom));
else if (y > 0)
matrix.postTranslate(0, -y);
}
}
}
public boolean canScrollHorizontally(int direction) {
matrix.getValues(m);
float x = Math.abs(m[Matrix.MTRANS_X]);
float scaleWidth = Math.round(origWidth * saveScale);
if (scaleWidth < width) {
return false;
} else {
if (x - direction <= 0)
return false; // reach left edge
else if (x + width - direction >= scaleWidth)
return false; // reach right edge
return true;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = View.MeasureSpec.getSize(widthMeasureSpec);
height = View.MeasureSpec.getSize(heightMeasureSpec);
locateImage();
}
protected void locateImage() {
if ((Float.compare(bmWidth, 0) * Float.compare(bmHeight, 0)) == 0) {
return;
}
// Fit to screen.
float scale;
float scaleX = width / bmWidth;
float scaleY = height / bmHeight;
scale = Math.min(scaleX, scaleY);
matrix.setScale(scale, scale);
setImageMatrix(matrix);
saveScale = 1f;
// Center the image
redundantYSpace = height - (scale * bmHeight);
redundantXSpace = width - (scale * bmWidth);
redundantYSpace /= 2;
redundantXSpace /= 2;
matrix.postTranslate(redundantXSpace, redundantYSpace);
origWidth = width - 2 * redundantXSpace;
origHeight = height - 2 * redundantYSpace;
right = width * saveScale - width - (2 * redundantXSpace * saveScale);
bottom = height * saveScale - height - (2 * redundantYSpace * saveScale);
setImageMatrix(matrix);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.control;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
public class PreviewImageView extends ImageView {
public PreviewImageView(Context context) {
super(context);
}
public PreviewImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.fragment;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Window;
public abstract class BaseDialogFragment extends DialogFragment {
protected Activity activity;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
return dialog;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = activity;
}
public abstract String getFragmentTag();
public void show(FragmentManager manager) {
super.show(manager, getFragmentTag());
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.fragment;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
public class BaseFragment extends Fragment {
private Handler handler;
protected Activity activity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handler = new Handler();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = activity;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.fragment;
import android.content.res.Resources;
import android.hardware.Camera;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.control.CameraPreview;
import com.yalantis.cameramodule.interfaces.CameraParamsChangedListener;
import com.yalantis.cameramodule.interfaces.FocusCallback;
import com.yalantis.cameramodule.interfaces.KeyEventsListener;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
import com.yalantis.cameramodule.interfaces.PhotoTakenCallback;
import com.yalantis.cameramodule.interfaces.RawPhotoTakenCallback;
import com.yalantis.cameramodule.model.FlashMode;
import com.yalantis.cameramodule.model.FocusMode;
import com.yalantis.cameramodule.model.HDRMode;
import com.yalantis.cameramodule.model.Quality;
import com.yalantis.cameramodule.model.Ratio;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import timber.log.Timber;
public class CameraFragment extends com.yalantis.cameramodule.fragment.BaseFragment implements PhotoSavedListener, KeyEventsListener, CameraParamsChangedListener, FocusCallback {
public static final String QUALITY = "quality";
public static final String RATIO = "ratio";
public static final String FOCUS_MODE = "focus_mode";
public static final String FLASH_MODE = "flash_mode";
public static final String HDR_MODE = "hdr_mode";
public static final String FRONT_CAMERA = "front_camera";
private PhotoTakenCallback callback;
private RawPhotoTakenCallback rawCallback;
private CameraParamsChangedListener paramsChangedListener;
private OrientationEventListener orientationListener;
private Quality quality;
private Ratio ratio;
private FlashMode flashMode;
private FocusMode focusMode;
private int mScreenWidth;
private int mScreenHeight;
private int mNavigationBarHeight;
private int mStatusBarHeight;
private List<Integer> zoomRatios;
private int zoomIndex;
private int minZoomIndex;
private int maxZoomIndex;
private Map<Ratio, Camera.Size> previewSizes;
private Map<Ratio, Map<Quality, Camera.Size>> pictureSizes;
private int layoutId;
private Camera camera;
private Camera.Parameters parameters;
private CameraPreview cameraPreview;
private ViewGroup previewContainer;
private View mCapture;
private ProgressBar progressBar;
private ImageButton flashModeButton;
private TextView mZoomRatioTextView;
private HDRMode hdrMode;
private boolean supportedHDR = false;
private boolean supportedFlash = false;
private int cameraId;
private int outputOrientation;
public static CameraFragment newInstance(int layoutId, PhotoTakenCallback callback, Bundle params) {
CameraFragment fragment = new CameraFragment();
fragment.layoutId = layoutId;
fragment.callback = callback;
fragment.setArguments(params);
return fragment;
}
public static CameraFragment newInstance(PhotoTakenCallback callback, Bundle params) {
CameraFragment fragment = new CameraFragment();
fragment.callback = callback;
fragment.layoutId = R.layout.fragment_camera;
fragment.setArguments(params);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean useFrontCamera = getArguments().getBoolean(FRONT_CAMERA, false);
camera = getCameraInstance(useFrontCamera);
if (camera == null) {
return;
}
initScreenParams();
parameters = camera.getParameters();
zoomRatios = parameters.getZoomRatios();
zoomIndex = minZoomIndex = 0;
maxZoomIndex = parameters.getMaxZoom();
previewSizes = buildPreviewSizesRatioMap(parameters.getSupportedPreviewSizes());
pictureSizes = buildPictureSizesRatioMap(parameters.getSupportedPictureSizes());
List<String> sceneModes = parameters.getSupportedSceneModes();
if (sceneModes != null) {
for (String mode : sceneModes) {
if (mode.equals(Camera.Parameters.SCENE_MODE_HDR)) {
supportedHDR = true;
break;
}
}
}
//it returns false positive
/*getActivity().getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);*/
List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes == null || flashModes.size() <= 1) { /* Device has no flash */
supportedFlash = false;
} else {
supportedFlash = true;
}
if (CameraConst.DEBUG) {
Timber.d("PictureSizesRatioMap:");
for (Ratio r : pictureSizes.keySet()) {
Timber.d(r.toString() + ":");
for (Quality q : pictureSizes.get(r).keySet()) {
Camera.Size size = pictureSizes.get(r).get(q);
if (size != null) {
Timber.d(q.toString() + ": " + size.width + "x" + size.height);
}
}
}
}
expandParams(getArguments());
initParams();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (camera == null) {
return inflater.inflate(R.layout.fragment_no_camera, container, false);
}
View view = inflater.inflate(layoutId, container, false);
try {
previewContainer = (ViewGroup) view.findViewById(R.id.camera_preview);
} catch (NullPointerException e) {
throw new RuntimeException("You should add container that extends ViewGroup for CameraPreview.");
}
ImageView canvasFrame = new ImageView(activity);
cameraPreview = new CameraPreview(activity, camera, canvasFrame, this, this);
previewContainer.addView(cameraPreview);
previewContainer.addView(canvasFrame);
cameraPreview.setFocusMode(focusMode);
progressBar = (ProgressBar) view.findViewById(R.id.progress);
mCapture = view.findViewById(R.id.capture);
if (mCapture != null) {
mCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
takePhoto();
}
});
}
flashModeButton = (ImageButton) view.findViewById(R.id.flash_mode);
if (flashModeButton != null) {
if (supportedFlash) {
flashModeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switchFlashMode();
onFlashModeChanged(flashMode.getId());
}
});
setFlashModeImage(flashMode);
} else {
flashModeButton.setVisibility(Button.GONE);
}
}
setPreviewContainerSize(mScreenWidth, mScreenHeight, ratio);
mZoomRatioTextView = (TextView) view.findViewById(R.id.zoom_ratio);
if (mZoomRatioTextView != null) {
setZoomRatioText(zoomIndex);
}
View cameraSettings = view.findViewById(R.id.camera_settings);
if (cameraSettings != null) {
view.findViewById(R.id.camera_settings).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
com.yalantis.cameramodule.fragment.CameraSettingsDialogFragment.newInstance(packSettings(), CameraFragment.this).show(getFragmentManager());
}
});
}
View controls = view.findViewById(R.id.controls_layout);
if (controls != null) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
params.topMargin = mStatusBarHeight;
params.bottomMargin = mNavigationBarHeight;
controls.setLayoutParams(params);
}
return view;
}
/**
* A safe way to get an instance of the Camera object.
*/
private Camera getCameraInstance(boolean useFrontCamera) {
Camera c = null;
try {
c = Camera.open(getCameraId(useFrontCamera));
} catch (Exception e) {
Timber.e(e, getString(R.string.lbl_camera_unavailable));
}
return c;
}
private int getCameraId(boolean useFrontCamera) {
int count = Camera.getNumberOfCameras();
int result = -1;
if (count > 0) {
result = 0;
Camera.CameraInfo info = new Camera.CameraInfo();
for (int i = 0; i < count; i++) {
Camera.getCameraInfo(i, info);
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK
&& !useFrontCamera) {
result = i;
break;
} else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT
&& useFrontCamera) {
result = i;
break;
}
}
}
cameraId = result;
return result;
}
@Override
public void onResume() {
super.onResume();
if (camera != null) {
try {
camera.reconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
if (orientationListener == null) {
initOrientationListener();
}
orientationListener.enable();
}
private void initScreenParams() {
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
mScreenWidth = metrics.widthPixels;
mScreenHeight = metrics.heightPixels;
mNavigationBarHeight = getNavigationBarHeight();
mStatusBarHeight = getStatusBarHeight();
}
private int getNavigationBarHeight() {
return getPixelSizeByName("navigation_bar_height");
}
private int getStatusBarHeight() {
return getPixelSizeByName("status_bar_height");
}
private int getPixelSizeByName(String name) {
Resources resources = getResources();
int resourceId = resources.getIdentifier(name, "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
return 0;
}
public void setCallback(PhotoTakenCallback callback) {
this.callback = callback;
}
public void setRawCallback(RawPhotoTakenCallback rawCallback) {
this.rawCallback = rawCallback;
}
public void setParamsChangedListener(CameraParamsChangedListener paramsChangedListener) {
this.paramsChangedListener = paramsChangedListener;
}
private Camera.PictureCallback pictureCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
if (callback != null) {
callback.photoTaken(data.clone(), outputOrientation);
}
camera.startPreview();
cameraPreview.onPictureTaken();
}
};
@Override
public void onFocused(Camera camera) {
camera.takePicture(null, rawPictureCallback, pictureCallback);
}
private Camera.PictureCallback rawPictureCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
if (rawCallback != null && data != null) {
rawCallback.rawPhotoTaken(data.clone());
}
}
};
@Override
public void onPause() {
super.onPause();
if (orientationListener != null) {
orientationListener.disable();
orientationListener = null;
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (camera != null) {
camera.release();
camera = null;
}
}
private void expandParams(Bundle params) {
if (params == null) {
params = new Bundle();
}
int id = 0;
if (params.containsKey(RATIO)) {
id = params.getInt(RATIO, 1);
}
ratio = Ratio.getRatioById(id);
id = 0;
if (params.containsKey(QUALITY)) {
id = params.getInt(QUALITY, 0);
}
quality = Quality.getQualityById(id);
id = 0;
if (params.containsKey(FOCUS_MODE)) {
id = params.getInt(FOCUS_MODE);
}
focusMode = FocusMode.getFocusModeById(id);
id = 0;
if (params.containsKey(FLASH_MODE)) {
id = params.getInt(FLASH_MODE);
}
flashMode = FlashMode.getFlashModeById(id);
id = 0;
if (params.containsKey(HDR_MODE)) {
id = params.getInt(HDR_MODE);
}
hdrMode = HDRMode.getHDRModeById(id);
}
private Bundle packSettings() {
Bundle params = new Bundle();
params.putInt(QUALITY, quality.getId());
params.putInt(RATIO, ratio.getId());
params.putInt(FOCUS_MODE, focusMode.getId());
params.putInt(HDR_MODE, hdrMode.getId());
return params;
}
private void initParams() {
setFlashMode(parameters, flashMode);
setPreviewSize(parameters, ratio);
setHDRMode(parameters, hdrMode);
setPictureSize(parameters, quality, ratio);
camera.setParameters(parameters);
}
@Override
public void onQualityChanged(int id) {
quality = Quality.getQualityById(id);
setPictureSize(parameters, quality, ratio);
camera.setParameters(parameters);
if (paramsChangedListener != null) {
paramsChangedListener.onQualityChanged(id);
}
}
@Override
public void onRatioChanged(int id) {
ratio = Ratio.getRatioById(id);
setPreviewSize(parameters, ratio);
setPictureSize(parameters, quality, ratio);
camera.setParameters(parameters);
setPreviewContainerSize(mScreenWidth, mScreenHeight, ratio);
if (paramsChangedListener != null) {
paramsChangedListener.onRatioChanged(id);
}
}
@Override
public void onHDRChanged(int id) {
hdrMode = HDRMode.getHDRModeById(id);
setHDRMode(parameters, hdrMode);
camera.setParameters(parameters);
if (paramsChangedListener != null) {
paramsChangedListener.onHDRChanged(id);
}
}
@Override
public void onFlashModeChanged(int id) {
if (paramsChangedListener != null) {
paramsChangedListener.onFlashModeChanged(id);
}
}
@Override
public void onFocusModeChanged(int id) {
focusMode = FocusMode.getFocusModeById(id);
cameraPreview.setFocusMode(focusMode);
if (paramsChangedListener != null) {
paramsChangedListener.onFocusModeChanged(id);
}
}
@Override
public void zoomIn() {
if (++zoomIndex > maxZoomIndex) {
zoomIndex = maxZoomIndex;
}
setZoom(zoomIndex);
}
@Override
public void zoomOut() {
if (--zoomIndex < minZoomIndex) {
zoomIndex = minZoomIndex;
}
setZoom(zoomIndex);
}
@Override
public void takePhoto() {
mCapture.setEnabled(false);
mCapture.setVisibility(View.INVISIBLE);
if (progressBar != null) {
progressBar.setVisibility(View.VISIBLE);
}
cameraPreview.takePicture();
}
private void setZoom(int index) {
parameters.setZoom(index);
camera.setParameters(parameters);
setZoomRatioText(index);
}
private void setZoomRatioText(int index) {
if (mZoomRatioTextView != null) {
float value = zoomRatios.get(index) / 100.0f;
mZoomRatioTextView.setText(getString(R.string.lbl_zoom_ratio_value, value));
}
}
private void switchFlashMode() {
switch (flashMode) {
case AUTO:
flashMode = FlashMode.ON;
break;
case ON:
flashMode = FlashMode.OFF;
break;
case OFF:
flashMode = FlashMode.AUTO;
break;
}
setFlashMode(parameters, flashMode);
setFlashModeImage(flashMode);
camera.setParameters(parameters);
}
private void setHDRMode(Camera.Parameters parameters, HDRMode hdrMode) {
if (supportedHDR && hdrMode == HDRMode.NONE) {
hdrMode = HDRMode.OFF;
}
switch (hdrMode) {
case ON:
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_HDR);
break;
case OFF:
parameters.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
break;
}
}
private void setFlashMode(Camera.Parameters parameters, FlashMode flashMode) {
switch (flashMode) {
case ON:
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
break;
case OFF:
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
break;
case AUTO:
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
break;
}
}
private void setFlashModeImage(FlashMode flashMode) {
switch (flashMode) {
case ON:
flashModeButton.setImageResource(R.drawable.cam_flash_fill_flash_icn);
break;
case OFF:
flashModeButton.setImageResource(R.drawable.cam_flash_off_icn);
break;
case AUTO:
flashModeButton.setImageResource(R.drawable.cam_flash_auto_icn);
break;
}
}
private void setPictureSize(Camera.Parameters parameters, Quality quality, Ratio ratio) {
Camera.Size size = pictureSizes.get(ratio).get(quality);
if (size != null) {
parameters.setPictureSize(size.width, size.height);
}
}
private void setPreviewSize(Camera.Parameters parameters, Ratio ratio) {
Camera.Size size = previewSizes.get(ratio);
parameters.setPreviewSize(size.width, size.height);
}
/**
* @param width Screen width
* @param height Screen height
* @param ratio Required ratio
*/
private void setPreviewContainerSize(int width, int height, Ratio ratio) {
height = (width / ratio.h) * ratio.w;
previewContainer.setLayoutParams(new RelativeLayout.LayoutParams(width, height));
}
private Map<Ratio, Map<Quality, Camera.Size>> buildPictureSizesRatioMap(List<Camera.Size> sizes) {
Map<Ratio, Map<Quality, Camera.Size>> map = new HashMap<>();
Map<Ratio, List<Camera.Size>> ratioListMap = new HashMap<>();
for (Camera.Size size : sizes) {
Ratio ratio = Ratio.pickRatio(size.width, size.height);
if (ratio != null) {
List<Camera.Size> sizeList = ratioListMap.get(ratio);
if (sizeList == null) {
sizeList = new ArrayList<>();
ratioListMap.put(ratio, sizeList);
}
sizeList.add(size);
}
}
for (Ratio r : ratioListMap.keySet()) {
List<Camera.Size> list = ratioListMap.get(r);
ratioListMap.put(r, sortSizes(list));
Map<Quality, Camera.Size> sizeMap = new HashMap<>();
int i = 0;
for (Quality q : Quality.values()) {
Camera.Size size = null;
if (i < list.size()) {
size = list.get(i++);
}
sizeMap.put(q, size);
}
map.put(r, sizeMap);
}
return map;
}
private List<Camera.Size> sortSizes(List<Camera.Size> sizes) {
int count = sizes.size();
while (count > 2) {
for (int i = 0; i < count - 1; i++) {
Camera.Size current = sizes.get(i);
Camera.Size next = sizes.get(i + 1);
if (current.width < next.width || current.height < next.height) {
sizes.set(i, next);
sizes.set(i + 1, current);
}
}
count--;
}
return sizes;
}
private Map<Ratio, Camera.Size> buildPreviewSizesRatioMap(List<Camera.Size> sizes) {
Map<Ratio, Camera.Size> map = new HashMap<>();
for (Camera.Size size : sizes) {
Ratio ratio = Ratio.pickRatio(size.width, size.height);
if (ratio != null) {
Camera.Size oldSize = map.get(ratio);
if (oldSize == null || (oldSize.width < size.width || oldSize.height < size.height)) {
map.put(ratio, size);
}
}
}
return map;
}
@Override
public void photoSaved(String path, String name) {
mCapture.setEnabled(true);
mCapture.setVisibility(View.VISIBLE);
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}
private void initOrientationListener() {
orientationListener = new OrientationEventListener(activity) {
@Override
public void onOrientationChanged(int orientation) {
if (camera != null && orientation != ORIENTATION_UNKNOWN) {
int newOutputOrientation = getCameraPictureRotation(orientation);
if (newOutputOrientation != outputOrientation) {
outputOrientation = newOutputOrientation;
Camera.Parameters params = camera.getParameters();
params.setRotation(outputOrientation);
try {
camera.setParameters(params);
} catch (Exception e) {
Timber.e(e, "Exception updating camera parameters in orientation change");
}
}
}
}
};
}
private int getCameraPictureRotation(int orientation) {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, info);
int rotation;
orientation = (orientation + 45) / 90 * 90;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - orientation + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + orientation) % 360;
}
return (rotation);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.Switch;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.adapters.ObjectToStringAdapter;
import com.yalantis.cameramodule.interfaces.CameraParamsChangedListener;
import com.yalantis.cameramodule.model.FocusMode;
import com.yalantis.cameramodule.model.HDRMode;
import com.yalantis.cameramodule.model.Quality;
import com.yalantis.cameramodule.model.Ratio;
import java.util.Arrays;
import java.util.List;
public class CameraSettingsDialogFragment extends BaseDialogFragment {
public static final String TAG = CameraSettingsDialogFragment.class.getSimpleName();
private CameraParamsChangedListener paramsChangedListener;
private Quality quality;
private Ratio ratio;
private FocusMode focusMode;
private HDRMode hdrMode;
private List<Ratio> ratios = Arrays.asList(Ratio.values());
private List<Quality> qualities = Arrays.asList(Quality.values());
private List<FocusMode> focusModes = Arrays.asList(FocusMode.values());
public static CameraSettingsDialogFragment newInstance(Bundle bundle, CameraParamsChangedListener listener) {
CameraSettingsDialogFragment fragment = new CameraSettingsDialogFragment();
fragment.setArguments(bundle);
fragment.paramsChangedListener = listener;
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
expandParams(getArguments());
}
private void expandParams(Bundle params) {
if (params == null) {
params = new Bundle();
}
int id = 0;
if (params.containsKey(CameraFragment.QUALITY)) {
id = params.getInt(CameraFragment.QUALITY, 0);
}
quality = Quality.getQualityById(id);
id = 0;
if (params.containsKey(CameraFragment.RATIO)) {
id = params.getInt(CameraFragment.RATIO, 0);
}
ratio = Ratio.getRatioById(id);
id = 0;
if (params.containsKey(CameraFragment.FOCUS_MODE)) {
id = params.getInt(CameraFragment.FOCUS_MODE);
}
focusMode = FocusMode.getFocusModeById(id);
id = 0;
if (params.containsKey(CameraFragment.HDR_MODE)) {
id = params.getInt(CameraFragment.HDR_MODE);
}
hdrMode = HDRMode.getHDRModeById(id);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_camera_params, container, false);
Spinner ratioSwitcher = (Spinner) view.findViewById(R.id.ratios);
ratioSwitcher.setAdapter(new ObjectToStringAdapter<>(activity, ratios));
ratioSwitcher.setSelection(ratios.indexOf(ratio));
ratioSwitcher.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (ratio == ratios.get(position)) {
return;
}
ratio = ratios.get(position);
onRatioChanged(ratio.getId());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Spinner qualitySwitcher = (Spinner) view.findViewById(R.id.qualities);
qualitySwitcher.setAdapter(new ObjectToStringAdapter<>(activity, qualities));
qualitySwitcher.setSelection(qualities.indexOf(quality));
qualitySwitcher.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (quality == qualities.get(position)) {
return;
}
quality = qualities.get(position);
onQualityChanged(quality.getId());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Spinner focusSwitcher = (Spinner) view.findViewById(R.id.focus_modes);
focusSwitcher.setAdapter(new ObjectToStringAdapter<>(activity, focusModes));
focusSwitcher.setSelection(focusModes.indexOf(focusMode));
focusSwitcher.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (focusMode == focusModes.get(position)) {
return;
}
focusMode = focusModes.get(position);
onFocusModeChanged(focusMode.getId());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
if (hdrMode == HDRMode.NONE) {
view.findViewById(R.id.relativeHdr).setVisibility(View.GONE);
} else {
view.findViewById(R.id.relativeHdr).setVisibility(View.VISIBLE);
Switch hdrSwitch = (Switch) view.findViewById(R.id.switchHDR);
hdrSwitch.setChecked(hdrMode == HDRMode.ON);
hdrSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onHDRChanged(isChecked ? HDRMode.ON.getId() : HDRMode.OFF.getId());
}
});
}
view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return view;
}
public void onQualityChanged(int id) {
if (paramsChangedListener != null) {
paramsChangedListener.onQualityChanged(id);
}
}
public void onHDRChanged(int id) {
if (paramsChangedListener != null) {
paramsChangedListener.onHDRChanged(id);
}
}
public void onRatioChanged(int id) {
if (paramsChangedListener != null) {
paramsChangedListener.onRatioChanged(id);
}
}
public void onFocusModeChanged(int id) {
if (paramsChangedListener != null) {
paramsChangedListener.onFocusModeChanged(id);
}
}
@Override
public String getFragmentTag() {
return TAG;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.fragment;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.edmodo.cropper.CropImageView;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.interfaces.PhotoCroppedCallback;
public class PhotoCropFragment extends BaseFragment {
private Bitmap bitmap;
private CropImageView cropView;
private PhotoCroppedCallback callback;
public static PhotoCropFragment newInstance(Bitmap bitmap) {
PhotoCropFragment fragment = new PhotoCropFragment();
fragment.bitmap = bitmap;
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_photo_crop, container, false);
}
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
cropView = (CropImageView) view.findViewById(R.id.photo);
cropView.setImageBitmap(bitmap);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
if (activity instanceof PhotoCroppedCallback) {
callback = (PhotoCroppedCallback) activity;
} else {
throw new RuntimeException(activity.getClass().getName() + " must implement " + PhotoCroppedCallback.class.getName());
}
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
cropView.setImageBitmap(bitmap);
}
public void applyCrop() {
callback.onPhotoCropped(bitmap.getWidth(), bitmap.getHeight(), cropView.getCroppedImage(), cropView.getActualCropRect());
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.fragment;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.yalantis.cameramodule.R;
import com.yalantis.cameramodule.control.PinchImageView;
public class PhotoPreviewFragment extends BaseFragment {
private Bitmap bitmap;
private PinchImageView imageView;
public static PhotoPreviewFragment newInstance(Bitmap bitmap) {
PhotoPreviewFragment fragment = new PhotoPreviewFragment();
fragment.bitmap = bitmap;
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_photo_preview, container, false);
}
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
imageView = (PinchImageView) view.findViewById(R.id.photo);
if (bitmap != null && !bitmap.isRecycled()) {
imageView.setImageBitmap(bitmap);
} else {
imageView.setImageResource(R.drawable.no_image);
}
}
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
imageView.setImageBitmap(bitmap);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
public interface CameraParamsChangedListener {
public void onQualityChanged(int id);
public void onRatioChanged(int id);
public void onFlashModeChanged(int id);
public void onHDRChanged(int id);
public void onFocusModeChanged(int id);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
import android.hardware.Camera;
public interface FocusCallback {
public void onFocused(Camera camera);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
import android.content.Context;
public interface Initializer {
public void init(Context context);
public void clear();
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
public interface KeyEventsListener {
public void zoomIn();
public void zoomOut();
public void takePhoto();
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
public interface PhotoActionsCallback {
public void onOpenPhotoPreview(String path, String name);
public void onAddNote(int zpid, String name);
public void onRetake(String name);
public void onDeletePhoto(String name);
public void onDeleteHomePhotos(int zpid);
public void onDeleteAddressPhotos(String address);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
import android.graphics.Bitmap;
import android.graphics.RectF;
public interface PhotoCroppedCallback {
/**
* @param width
* width before crop
* @param height
* height before crop
* @param croppedBitmap
* cropped bitmap
* @param cropRect
* cropping rectangle
*/
public void onPhotoCropped(int width, int height, Bitmap croppedBitmap, RectF cropRect);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
public interface PhotoSavedListener {
public void photoSaved(String path, String name);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
public interface PhotoTakenCallback {
public void photoTaken(byte[] data, int orientation);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
public interface RawPhotoTakenCallback {
public void rawPhotoTaken(byte[] data);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.interfaces;
import android.graphics.Bitmap;
import com.yalantis.cameramodule.util.ManagedTarget;
public interface StorageCallback {
public void setBitmap(String path, Bitmap bitmap);
public void addTarget(ManagedTarget target);
public void removeTarget(ManagedTarget target);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.manager;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.text.TextUtils;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.PicassoTools;
import com.squareup.picasso.Target;
import com.yalantis.cameramodule.interfaces.Initializer;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
import com.yalantis.cameramodule.interfaces.StorageCallback;
import com.yalantis.cameramodule.util.CropPhotoTask;
import com.yalantis.cameramodule.util.ManagedTarget;
import com.yalantis.cameramodule.util.RotatePhotoTask;
import com.yalantis.cameramodule.util.ScaleTransformation;
public enum ImageManager implements Initializer, StorageCallback {
i;
private Context context;
private Picasso picasso;
private HashSet<ManagedTarget> targets;
private Map<String, WeakReference<Bitmap>> bitmapMap;
@Override
public void init(Context context) {
this.context = context;
this.picasso = Picasso.with(context);
bitmapMap = new HashMap<>();
targets = new HashSet<>();
}
public void loadPhoto(String path, int width, int height, Target target) {
File photo = !TextUtils.isEmpty(path) ? new File(path) : null;
if (path == null) {
target.onBitmapFailed(null);
}
Bitmap bitmap = getBitmap(path);
if (bitmap != null && !bitmap.isRecycled()) {
target.onBitmapLoaded(bitmap, Picasso.LoadedFrom.MEMORY);
} else {
ManagedTarget managedTarget = new ManagedTarget(target, path, this);
Picasso.with(context)
.load(photo)
.skipMemoryCache()
.config(Bitmap.Config.ARGB_8888)
.transform(new ScaleTransformation(width, height))
.into(managedTarget);
}
}
public void cropBitmap(String path, int width, int height, Bitmap croppedBitmap, RectF rect, PhotoSavedListener callback) {
setBitmap(path, croppedBitmap);
new CropPhotoTask(path, width, height, rect, callback).execute();
}
public Bitmap rotatePhoto(String path, float angle) {
Bitmap bitmap = getBitmap(path);
if (bitmap != null && !bitmap.isRecycled()) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
setBitmap(path, bitmap);
new RotatePhotoTask(path, angle, null).execute();
return bitmap;
}
private Bitmap getBitmap(String path) {
return bitmapMap.get(path) != null ? bitmapMap.get(path).get() : null;
}
@Override
public void clear() {
synchronized (bitmapMap) {
for (WeakReference<Bitmap> reference : bitmapMap.values()) {
if (reference != null) {
Bitmap bitmap = reference.get();
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.recycle();
}
}
}
bitmapMap.clear();
}
PicassoTools.clearCache(picasso);
}
@Override
public void setBitmap(String path, Bitmap bitmap) {
bitmapMap.put(path, new WeakReference<>(bitmap));
}
@Override
public void addTarget(ManagedTarget target) {
removeTarget(target);
targets.add(target);
}
@Override
public void removeTarget(ManagedTarget target) {
if (targets.contains(target)) {
targets.remove(target);
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.manager;
import timber.log.Timber;
import android.content.Context;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.interfaces.Initializer;
public enum LoggerManager implements Initializer {
i;
private Context context;
@Override
public void init(Context context) {
this.context = context;
if (CameraConst.DEBUG) {
Timber.plant(new Timber.DebugTree());
} else {
Timber.plant(new CrashReportingTree());
}
}
/** A tree which logs important information for crash reporting. */
private static class CrashReportingTree extends Timber.DebugTree {
@Override
public void d(String message, Object... args) {
}
@Override
public void d(Throwable t, String message, Object... args) {
}
@Override
public void i(String message, Object... args) {
}
@Override
public void i(Throwable t, String message, Object... args) {
}
@Override
public void w(String message, Object... args) {
}
@Override
public void w(Throwable t, String message, Object... args) {
}
@Override
public void e(String message, Object... args) {
super.e(message, args);
}
@Override
public void e(Throwable t, String message, Object... args) {
super.e(t, message, args);
}
}
@Override
public void clear() {
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.manager;
import java.util.HashSet;
import java.util.Set;
import android.content.Context;
import android.content.SharedPreferences;
import com.yalantis.cameramodule.interfaces.Initializer;
import com.yalantis.cameramodule.model.CachedValue;
public enum SharedPrefManager implements Initializer {
i;
private static final String NAME = "sharedPrefs";
public static final String OPEN_PHOTO_PREVIEW = "open_photo_preview";
public static final String CAMERA_RATIO = "camera_ratio";
public static final String CAMERA_QUALITY = "camera_quality";
public static final String CAMERA_FLASH_MODE = "camera_flash_mode";
public static final String CAMERA_HDR_MODE = "camera_hdr_mode";
public static final String CAMERA_FOCUS_MODE = "camera_focus_mode";
public static final String USE_FRONT_CAMERA = "use_front_camera";
private static SharedPreferences sp;
private Set<CachedValue> cachedValues;
private CachedValue<Boolean> openPhotoPreview;
private CachedValue<Integer> cameraRatio;
private CachedValue<Integer> cameraQuality;
private CachedValue<Integer> cameraFlashMode;
private CachedValue<Integer> isCameraHDRMode;
private CachedValue<Integer> cameraFocusMode;
private CachedValue<Boolean> useFrontCamera;
@Override
public void init(Context context) {
sp = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
CachedValue.initialize(sp);
cachedValues = new HashSet<>();
cachedValues.add(openPhotoPreview = new CachedValue<>(OPEN_PHOTO_PREVIEW, true, Boolean.class));
cachedValues.add(isCameraHDRMode = new CachedValue<>(CAMERA_HDR_MODE, 0, Integer.class));
cachedValues.add(cameraRatio = new CachedValue<>(CAMERA_RATIO, 0, Integer.class));
cachedValues.add(cameraQuality = new CachedValue<>(CAMERA_QUALITY, 0, Integer.class));
cachedValues.add(cameraFlashMode = new CachedValue<>(CAMERA_FLASH_MODE, 0, Integer.class));
cachedValues.add(cameraFocusMode = new CachedValue<>(CAMERA_FOCUS_MODE, 0, Integer.class));
cachedValues.add(useFrontCamera = new CachedValue<>(USE_FRONT_CAMERA, false, Boolean.class));
}
public void setHDRMode(int isHDR) {
this.isCameraHDRMode.setValue(isHDR);
}
public int isHDR() {
return isCameraHDRMode.getValue();
}
public boolean isOpenPhotoPreview() {
return openPhotoPreview.getValue();
}
public void setOpenPhotoPreview(boolean enabled) {
this.openPhotoPreview.setValue(enabled);
}
public int getCameraRatio() {
return cameraRatio.getValue();
}
public void setCameraRatio(int cameraRatio) {
this.cameraRatio.setValue(cameraRatio);
}
public int getCameraQuality() {
return cameraQuality.getValue();
}
public void setCameraQuality(int cameraQuality) {
this.cameraQuality.setValue(cameraQuality);
}
public int getCameraFlashMode() {
return cameraFlashMode.getValue();
}
public void setCameraFlashMode(int cameraFlashMode) {
this.cameraFlashMode.setValue(cameraFlashMode);
}
public int getCameraFocusMode() {
return cameraFocusMode.getValue();
}
public void setCameraFocusMode(int cameraFocusMode) {
this.cameraFocusMode.setValue(cameraFocusMode);
}
public boolean useFrontCamera() {
return useFrontCamera.getValue();
}
public void setUseFrontCamera(boolean frontCamera) {
this.useFrontCamera.setValue(frontCamera);
}
@Override
public void clear() {
for (CachedValue value : cachedValues) {
value.clear();
}
sp.edit().clear().commit();
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
import android.content.SharedPreferences;
public class CachedValue<T> {
private static SharedPreferences sharedPref;
private SharedPreferences sp;
private T value;
private T defValue;
private Class type;
private String name;
private boolean loaded = false;
public CachedValue(String name, Class type) {
this(name, null, null, type);
}
public CachedValue(String name, T defValue, Class type) {
this(name, null, defValue, type);
}
public CachedValue(String name, T value, T defValue, Class type) {
this.sp = sharedPref;
this.name = name;
this.type = type;
this.loaded = value != null;
this.value = value;
this.defValue = defValue;
}
public void setValue(T value) {
loaded = true;
write(this.value = value);
}
public T getValue() {
if (!loaded) {
this.value = load();
loaded = true;
}
return this.value;
}
public String getName() {
return name;
}
private void write(T value) {
SharedPreferences.Editor editor = sp.edit();
if (value instanceof String) {
editor.putString(name, (String) value);
} else if (value instanceof Integer) {
editor.putInt(name, (Integer) value);
} else if (value instanceof Float) {
editor.putFloat(name, (Float) value);
} else if (value instanceof Long) {
editor.putLong(name, (Long) value);
} else if (value instanceof Boolean) {
editor.putBoolean(name, (Boolean) value);
}
editor.commit();
}
@SuppressWarnings("unchecked")
private T load() {
if (type == String.class) {
return (T) sp.getString(name, (String) defValue);
} else if (type == Integer.class) {
return (T) Integer.valueOf(sp.getInt(name, (Integer) defValue));
} else if (type == Float.class) {
return (T) Float.valueOf(sp.getFloat(name, (Float) defValue));
} else if (type == Long.class) {
return (T) Long.valueOf(sp.getLong(name, (Long) defValue));
} else if (type == Boolean.class) {
return (T) Boolean.valueOf(sp.getBoolean(name, (Boolean) defValue));
}
return null;
}
public void delete() {
sp.edit().remove(name).commit();
clear();
}
public static void initialize(SharedPreferences sp) {
CachedValue.sharedPref = sp;
}
public void setSharedPreferences(SharedPreferences sp) {
this.sp = sp;
}
public void clear() {
loaded = false;
this.value = null;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
public enum FlashMode {
ON(0, "On"), AUTO(1, "Auto"), OFF(2, "Off");
private int id;
private String name;
FlashMode(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public static FlashMode getFlashModeById(int id) {
for (FlashMode mode : values()) {
if (mode.id == id) {
return mode;
}
}
return null;
}
@Override
public String toString() {
return name;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
public enum FocusMode {
AUTO(0, "Auto"), TOUCH(1, "Touch");
private int id;
private String name;
FocusMode(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public static FocusMode getFocusModeById(int id) {
for (FocusMode mode : values()) {
if (mode.id == id) {
return mode;
}
}
return null;
}
@Override
public String toString() {
return name;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
public enum HDRMode {
NONE(0, "None"), ON(1, "On"), OFF(2, "Off");
private int id;
private String name;
HDRMode(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public static HDRMode getHDRModeById(int id) {
for (HDRMode mode : values()) {
if (mode.id == id) {
return mode;
}
}
return null;
}
@Override
public String toString() {
return name;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
public class PictureSize {
public int width;
public int height;
public Ratio ratio;
public PictureSize(int width, int height, Ratio ratio) {
this.width = width;
this.height = height;
this.ratio = ratio;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
public enum Quality {
HIGH(0, "High"), MEDIUM(1, "Medium"), LOW(2, "Low");
private int id;
private String name;
Quality(int id, String name) {
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public static Quality getQualityById(int id) {
for (Quality mode : values()) {
if (mode.id == id) {
return mode;
}
}
return null;
}
@Override
public String toString() {
return name;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.model;
public enum Ratio {
R_4x3(0, 4, 3), R_16x9(1, 16, 9);
private int id;
public int w;
public int h;
Ratio(int id, int w, int h) {
this.id = id;
this.w = w;
this.h = h;
}
public int getId() {
return id;
}
public static Ratio getRatioById(int id) {
for (Ratio ratio : values()) {
if (ratio.id == id) {
return ratio;
}
}
return null;
}
public static Ratio pickRatio(int width, int height) {
for (Ratio ratio : values()) {
if (width / ratio.w == height / ratio.h) {
return ratio;
}
}
return null;
}
@Override
public String toString() {
return w + ":" + h;
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import timber.log.Timber;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.RectF;
import android.os.AsyncTask;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
public class CropPhotoTask extends AsyncTask<Void, Void, Void> {
private String path;
private int width;
private int height;
private RectF rect;
private PhotoSavedListener callback;
public CropPhotoTask(String path, int width, int height, RectF rect, PhotoSavedListener callback) {
this.path = path;
this.rect = rect;
this.width = width;
this.height = height;
this.callback = callback;
}
@Override
protected Void doInBackground(Void... params) {
Bitmap src = BitmapFactory.decodeFile(path);
float koefW = (float) width / (float) src.getWidth();
float koefH = (float) height / (float) src.getHeight();
rect.top /= koefH;
rect.left /= koefW;
rect.right /= koefW;
rect.bottom /= koefH;
width = (int) rect.width();
height = (int) rect.height();
Bitmap bitmap = Bitmap.createBitmap(src, (int) rect.left, (int) rect.top, width, height);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(path));
bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos);
} catch (FileNotFoundException e) {
Timber.e(e, "File not found: " + e.getMessage());
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
}
bitmap.recycle();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (callback != null) {
callback.photoSaved(path, null);
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import com.yalantis.cameramodule.interfaces.StorageCallback;
public class ManagedTarget implements Target {
private Target target;
private String path;
private StorageCallback callback;
public ManagedTarget(Target target, String path, StorageCallback callback) {
this.target = target;
this.path = path;
this.callback = callback;
callback.addTarget(this);
}
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
target.onBitmapLoaded(bitmap, from);
callback.setBitmap(path, bitmap);
callback.removeTarget(this);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
target.onBitmapFailed(errorDrawable);
callback.removeTarget(this);
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
target.onPrepareLoad(placeHolderDrawable);
}
@Override
public int hashCode() {
return path.hashCode();
}
@Override
public boolean equals(Object o) {
if (super.equals(o)) {
return true;
}
if (o == null) {
return false;
}
if (o.getClass() != this.getClass()) {
return false;
}
ManagedTarget other = (ManagedTarget) o;
return other.path.equals(path);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import java.io.File;
public class PhotoUtil {
public static void deletePhoto(String path) {
File file = new File(path);
file.delete();
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import timber.log.Timber;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.AsyncTask;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
public class RotatePhotoTask extends AsyncTask<Void, Void, Void> {
private String path;
private float angle;
private PhotoSavedListener callback;
public RotatePhotoTask(String path, float angle, PhotoSavedListener callback) {
this.path = path;
this.angle = angle;
this.callback = callback;
}
@Override
protected Void doInBackground(Void... params) {
Bitmap bitmap = BitmapFactory.decodeFile(path); // todo NPE
Matrix matrix = new Matrix();
matrix.postRotate(angle);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(path));
bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos);
} catch (FileNotFoundException e) {
Timber.e(e, "File not found: " + e.getMessage());
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
}
bitmap.recycle();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (callback != null) {
callback.photoSaved(path, null);
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import timber.log.Timber;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
public class SavingBitmapTask extends AsyncTask<Void, Void, Void> {
private Bitmap bitmap;
private String path;
private PhotoSavedListener callback;
public SavingBitmapTask(Bitmap bitmap, String path, PhotoSavedListener callback) {
this.bitmap = bitmap;
this.path = path;
this.callback = callback;
}
@Override
protected Void doInBackground(Void... params) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(new File(path));
if (bitmap != null && !bitmap.isRecycled()) {
bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos);
}
} catch (FileNotFoundException e) {
Timber.e(e, "File not found: " + e.getMessage());
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
if (callback != null) {
callback.photoSaved(path, null);
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import timber.log.Timber;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.os.AsyncTask;
import android.os.Environment;
import com.yalantis.cameramodule.CameraConst;
import com.yalantis.cameramodule.interfaces.PhotoSavedListener;
public class SavingPhotoTask extends AsyncTask<Void, Void, File> {
private byte[] data;
private String name;
private String path;
private int orientation;
private PhotoSavedListener callback;
public SavingPhotoTask(byte[] data, String name, String path, int orientation) {
this(data, name, path, orientation, null);
}
public SavingPhotoTask(byte[] data, String name, String path, int orientation, PhotoSavedListener callback) {
this.data = data;
this.name = name;
this.path = path;
this.orientation = orientation;
this.callback = callback;
}
@Override
protected File doInBackground(Void... params) {
File photo = getOutputMediaFile();
if (photo == null) {
Timber.e("Error creating media file, check storage permissions");
return null;
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(photo);
if (orientation == ExifInterface.ORIENTATION_UNDEFINED) {
saveByteArray(fos, data);
} else {
saveByteArrayWithOrientation(fos, data, orientation);
}
} catch (FileNotFoundException e) {
Timber.e(e, "File not found: " + e.getMessage());
} catch (IOException e) {
Timber.e(e, "File write failure: " + e.getMessage());
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
}
return photo;
}
private void saveByteArray(FileOutputStream fos, byte[] data) throws IOException {
long time = System.currentTimeMillis();
fos.write(data);
Timber.d("saveByteArray: %1dms", System.currentTimeMillis() - time);
}
private void saveByteArrayWithOrientation(FileOutputStream fos, byte[] data, int orientation) {
long totalTime = System.currentTimeMillis();
long time = System.currentTimeMillis();
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Timber.d("decodeByteArray: %1dms", System.currentTimeMillis() - time);
time = System.currentTimeMillis();
if (orientation != 0 && bitmap.getWidth() > bitmap.getHeight()) {
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Timber.d("createBitmap: %1dms", System.currentTimeMillis() - time);
}
time = System.currentTimeMillis();
bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos);
Timber.d("compress: %1dms", System.currentTimeMillis() - time);
bitmap.recycle();
Timber.d("saveByteArrayWithOrientation: %1dms", System.currentTimeMillis() - totalTime);
}
@Override
protected void onPostExecute(File file) {
super.onPostExecute(file);
photoSaved(file);
}
private void photoSaved(File photo) {
if (photo != null) {
if (callback != null) {
callback.photoSaved(photo.getPath(), photo.getName());
}
}
}
/**
* Create a File for saving an image
*/
private File getOutputMediaFile() {
// To be safe, we should check that the SDCard is mounted
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Timber.e("External storage " + Environment.getExternalStorageState());
return null;
}
File dir = new File(path);
// Create the storage directory if it doesn't exist
if (!dir.exists()) {
if (!dir.mkdirs()) {
Timber.e("Failed to create directory");
return null;
}
}
return new File(dir.getPath() + File.separator + name);
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Zillow
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.yalantis.cameramodule.util;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import com.squareup.picasso.Transformation;
public class ScaleTransformation implements Transformation {
private float width;
private float height;
public ScaleTransformation(float width, float height) {
this.width = width;
this.height = height;
}
@Override
public Bitmap transform(Bitmap source) {
float sWidth = source.getWidth();
float sHeight = source.getHeight();
float xScale;
float yScale;
if (sWidth < sHeight) {
yScale = height / sHeight;
xScale = yScale;
} else {
xScale = width / sWidth;
yScale = xScale;
}
Matrix matrix = new Matrix();
matrix.postScale(xScale, yScale);
Bitmap scaledBitmap = Bitmap.createBitmap(source, 0, 0, (int) sWidth, (int) sHeight, matrix, true);
scaledBitmap.getWidth();
scaledBitmap.getHeight();
if (scaledBitmap != source) {
source.recycle();
}
return scaledBitmap;
}
@Override
public String key() {
return "scaleTo" + width + "x" + height;
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" android:state_pressed="true" android:state_selected="true"/>
<item android:drawable="@android:color/white" android:state_selected="true"/>
<item android:drawable="@android:color/white" android:state_pressed="true"/>
<item android:drawable="@android:color/transparent"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_camera_capture" android:state_pressed="false"/>
<item android:drawable="@drawable/ic_camera_capture_pressed" android:state_pressed="true"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/camera_params_background"
style="@style/LinearLayout.ActionsDialog">
<RelativeLayout
style="@style/RelativeLayout.SettingsItem">
<TextView
android:text="@string/lbl_quality"
style="@style/TextView.CameraSettingsItemTitle"/>
<Spinner
android:id="@+id/qualities"
style="@style/Spinner.CameraParamsItem"/>
</RelativeLayout>
<RelativeLayout
style="@style/RelativeLayout.SettingsItem">
<TextView
android:text="@string/lbl_ratio"
style="@style/TextView.CameraSettingsItemTitle"/>
<Spinner
android:id="@+id/ratios"
style="@style/Spinner.CameraParamsItem"/>
</RelativeLayout>
<RelativeLayout style="@style/RelativeLayout.SettingsItem">
<TextView
android:text="@string/lbl_focus_mode"
style="@style/TextView.CameraSettingsItemTitle"/>
<Spinner
android:id="@+id/focus_modes"
style="@style/Spinner.CameraParamsItem"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeHdr"
style="@style/RelativeLayout.SettingsItem">
<TextView
android:text="@string/lbl_hdr"
style="@style/TextView.CameraSettingsItemTitle"/>
<Switch
android:id="@+id/switchHDR"
style="@style/Switch.SettingsItem"/>
</RelativeLayout>
<Button
android:id="@+id/close"
android:text="@string/lbl_close"
android:textColor="@android:color/white"
android:layout_marginTop="@dimen/base_padding"
style="@style/Button.ActionDialog"/>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/camera_background">
<FrameLayout
android:id="@+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout
android:layout_below="@id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/sheet_shadow"/>
<RelativeLayout
android:id="@+id/controls_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<TextView
android:id="@+id/zoom_ratio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@android:color/white"
android:layout_margin="@dimen/small_margin"
android:text="@string/lbl_zoom_ratio_value"/>
<ImageButton
android:id="@+id/flash_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="@drawable/cam_flash_auto_icn"
android:background="@null"
android:layout_margin="@dimen/small_margin"/>
<ImageButton
android:id="@+id/capture"
android:src="@drawable/camera_capture"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/small_margin"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@id/capture"
android:layout_alignTop="@id/capture"
android:layout_alignEnd="@id/capture"
android:layout_alignBottom="@id/capture"
android:visibility="gone"/>
<ImageButton
android:id="@+id/camera_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/base_padding"
android:layout_marginRight="@dimen/medium_margin"
android:src="@android:drawable/ic_menu_more"
android:background="@null"/>
</RelativeLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="@dimen/base_padding"
android:textStyle="bold"
android:text="@string/lbl_camera_unavailable"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.edmodo.cropper.CropImageView
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.yalantis.cameramodule.control.PinchImageView
android:id="@+id/photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/base_padding"
android:textColor="@android:color/black"/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/base_padding"
android:textColor="@android:color/white"/>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/apply"
android:showAsAction="always"
android:onClick="apply"
android:title="@string/lbl_string_apply"/>
<item
android:id="@+id/cancel"
android:showAsAction="always"
android:onClick="cancel"
android:title="@string/lbl_cancel"/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/delete"
android:showAsAction="ifRoom"
android:onClick="deletePhoto"
android:title="@string/lbl_delete"/>
<item
android:id="@+id/rotate_left"
android:showAsAction="ifRoom"
android:onClick="rotateLeft"
android:title="@string/lbl_left"/>
<item
android:id="@+id/rotate_right"
android:showAsAction="ifRoom"
android:onClick="rotateRight"
android:title="@string/lbl_right"/>
<item
android:id="@+id/crop"
android:showAsAction="ifRoom"
android:onClick="openPhotoCropper"
android:title="@string/lbl_crop"/>
</menu>
\ No newline at end of file
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<resources>
<!-- Declare custom theme attributes that allow changing which styles are
used for button bars depending on the API level.
?android:attr/buttonBarStyle is new as of API 11 so this is
necessary to support previous API levels. -->
<declare-styleable name="ButtonBarContainerTheme">
<attr name="metaButtonBarStyle" format="reference"/>
<attr name="metaButtonBarButtonStyle" format="reference"/>
</declare-styleable>
</resources>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<resources>
<color name="black_overlay">#66000000</color>
<color name="camera_background">#777</color>
<color name="camera_params_background">#99000000</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<resources>
<dimen name="base_padding">15dp</dimen>
<dimen name="small_margin">10dp</dimen>
<dimen name="medium_margin">20dp</dimen>
<dimen name="camera_screen_dialog_spinner_width">100dp</dimen>
<dimen name="settings_item_padding">5dp</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<resources>
<string name="app_name">CameraModule</string>
<string name="lbl_string_apply">Apply</string>
<string name="lbl_cancel">Cancel</string>
<string name="lbl_delete">Delete</string>
<string name="lbl_left">Left</string>
<string name="lbl_right">Right</string>
<string name="lbl_crop">Crop</string>
<string name="lbl_camera_unavailable">Camera is not available (in use or does not exist).\nPlease close applications, that may use camera.
</string>
<string name="lbl_zoom_ratio_value">Zoom: %1.2fx</string>
<string name="lbl_open_photo_preview">Open preview photo after shot</string>
<string name="lbl_settings">Settings</string>
<string name="lbl_hdr">HDR</string>
<string name="lbl_close">Close</string>
<string name="lbl_focus_mode">Focus mode</string>
<string name="lbl_ratio">Ratio</string>
<string name="lbl_quality">Quality</string>
<string name="lbl_take_another">Take another</string>
<string name="lbl_photo_crop">Photo crop</string>
<string name="lbl_photo_preview">lbl_photo_preview</string>
</resources>
<!--
~ The MIT License (MIT)
~
~ Copyright (c) 2014 Zillow
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is furnished
~ to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
~ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
~ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<resources>
<style name="FullscreenTheme" parent="android:Theme.Holo">
<item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowBackground">@null</item>
<item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
<item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
</style>
<style name="FullscreenActionBarStyle" parent="android:Widget.Holo.ActionBar">
<item name="android:background">@color/black_overlay</item>
</style>
<style name="Theme.TranslucentNavigationBar" parent="android:Theme.Holo.Light.NoActionBar.TranslucentDecor">
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowFullscreen">false</item>
</style>
<style name="Theme.TransparentActionBar" parent="android:Theme.Holo.NoActionBar.TranslucentDecor">
<item name="android:actionBarStyle">@style/Widget.ActionBar.Transparent</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowActionBar">true</item>
<item name="android:windowNoTitle">false</item>
</style>
<style name="Widget.ActionBar.Transparent" parent="@android:style/Widget.Holo.ActionBar">
<item name="android:background">#55000000</item>
</style>
<!--RelativeLayout-->
<style name="RelativeLayout"/>
<style name="RelativeLayout.SettingsItem" parent="RelativeLayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">@dimen/base_padding</item>
</style>
<!--Switch-->
<style name="Switch"/>
<style name="Switch.SettingsItem" parent="Switch">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_centerVertical">true</item>
</style>
<!--Spinner-->
<style name="Spinner"/>
<style name="Spinner.CameraParamsItem" parent="Spinner">
<item name="android:layout_width">@dimen/camera_screen_dialog_spinner_width</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_centerVertical">true</item>
</style>
<!-- TextView-->
<style name="TextView"/>
<style name="TextView.SettingsItemTitle" parent="TextView">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">@dimen/settings_item_padding</item>
<item name="android:layout_alignParentLeft">true</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="TextView.SettingsItemValue" parent="TextView">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">@dimen/settings_item_padding</item>
<item name="android:layout_alignParentRight">true</item>
<item name="android:layout_centerVertical">true</item>
</style>
<style name="TextView.CameraSettingsItemTitle" parent="TextView.SettingsItemTitle">
<item name="android:textColor">@android:color/white</item>
</style>
<!-- LinearLayout-->
<style name="LinearLayout"/>
<style name="LinearLayout.ActionsDialog" parent="LinearLayout">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/input</item>
<item name="android:padding">@dimen/base_padding</item>
<item name="android:gravity">center</item>
<item name="android:orientation">vertical</item>
</style>
<!-- Button-->
<style name="Button"/>
<style name="Button.ActionDialog" parent="Button">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
</resources>
......@@ -40,8 +40,10 @@ dependencies {
compile project(':openCVLibrary2411')
compile 'com.parse.bolts:bolts-android:1.2.1'
compile 'com.google.code.gson:gson:2.3'
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
compile 'commons-io:commons-io:2.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.5.3@aar') {
transitive = true;
}
compile project(':CameraModule')
}
......@@ -5,15 +5,18 @@
*/
package com.aluxoft.earrecognition.intents;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import com.aluxoft.earrecognition.EarIdentifier;
import com.aluxoft.earrecognition.utils.ImageUtils;
import com.crashlytics.android.Crashlytics;
import com.yalantis.cameramodule.activity.CameraActivity;
import java.io.File;
import java.io.IOException;
......@@ -43,6 +46,7 @@ public class IntentSearchFeatures extends Activity{
public boolean takePhoto() {
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
location = ImageUtils.createTempImageFile();
......@@ -60,6 +64,19 @@ public class IntentSearchFeatures extends Activity{
return false;
}
return true;
/*
Intent intent = new Intent(this, CameraActivity.class);
File storage = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
intent.putExtra(CameraActivity.PATH, storage);
intent.putExtra(CameraActivity.OPEN_PHOTO_PREVIEW, true);
//intent.putExtra(CameraActivity.LAYOUT_ID, R.layout.fragment_camera_custom);
intent.putExtra(CameraActivity.USE_FRONT_CAMERA, false);
startActivity(intent);
return true;
*/
}
......
include ':app'
include ':app', ':CameraModule'
include ':openCVLibrary2411'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment