├── .gitignore ├── CameraModule ├── .gitignore ├── build.gradle ├── proguard-rules.txt └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ ├── squareup │ │ └── picasso │ │ │ └── PicassoTools.java │ │ └── yalantis │ │ └── cameramodule │ │ ├── CameraConst.java │ │ ├── ManagerInitializer.java │ │ ├── activity │ │ ├── BaseActivity.java │ │ ├── BasePhotoActivity.java │ │ ├── CameraActivity.java │ │ ├── PhotoCropActivity.java │ │ └── PhotoPreviewActivity.java │ │ ├── adapters │ │ ├── BaseListAdapter.java │ │ └── ObjectToStringAdapter.java │ │ ├── control │ │ ├── CameraPreview.java │ │ ├── PinchImageView.java │ │ └── PreviewImageView.java │ │ ├── fragment │ │ ├── BaseDialogFragment.java │ │ ├── BaseFragment.java │ │ ├── CameraFragment.java │ │ ├── CameraSettingsDialogFragment.java │ │ ├── PhotoCropFragment.java │ │ └── PhotoPreviewFragment.java │ │ ├── interfaces │ │ ├── CameraParamsChangedListener.java │ │ ├── FocusCallback.java │ │ ├── Initializer.java │ │ ├── KeyEventsListener.java │ │ ├── PhotoActionsCallback.java │ │ ├── PhotoCroppedCallback.java │ │ ├── PhotoSavedListener.java │ │ ├── PhotoTakenCallback.java │ │ ├── RawPhotoTakenCallback.java │ │ └── StorageCallback.java │ │ ├── manager │ │ ├── ImageManager.java │ │ ├── LoggerManager.java │ │ └── SharedPrefManager.java │ │ ├── model │ │ ├── CachedValue.java │ │ ├── FlashMode.java │ │ ├── FocusMode.java │ │ ├── HDRMode.java │ │ ├── PictureSize.java │ │ ├── Quality.java │ │ └── Ratio.java │ │ └── util │ │ ├── CropPhotoTask.java │ │ ├── ManagedTarget.java │ │ ├── PhotoUtil.java │ │ ├── RotatePhotoTask.java │ │ ├── SavingBitmapTask.java │ │ ├── SavingPhotoTask.java │ │ └── ScaleTransformation.java │ └── res │ ├── drawable-hdpi │ ├── ic_camera_capture.png │ └── ic_camera_capture_pressed.png │ ├── drawable-mdpi │ ├── ic_camera_capture.png │ └── ic_camera_capture_pressed.png │ ├── drawable-xhdpi │ ├── ic_camera_capture.png │ └── ic_camera_capture_pressed.png │ ├── drawable-xxhdpi │ ├── cam_flash_auto_icn.png │ ├── cam_flash_fill_flash_icn.png │ ├── cam_flash_off_icn.png │ ├── ic_camera_capture.png │ └── ic_camera_capture_pressed.png │ ├── drawable │ ├── bg_transparent_clickable.xml │ ├── camera_capture.xml │ ├── input.9.png │ ├── no_image.png │ └── sheet_shadow.png │ ├── layout │ ├── activity_photo.xml │ ├── activity_with_fragment.xml │ ├── dialog_camera_params.xml │ ├── fragment_camera.xml │ ├── fragment_no_camera.xml │ ├── fragment_photo_crop.xml │ ├── fragment_photo_preview.xml │ ├── object_to_string_dropdown_list_item.xml │ └── object_to_string_list_item.xml │ ├── menu │ ├── photo_crop_options.xml │ └── photo_preview_options.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.txt └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yalantis │ │ └── sample │ │ ├── App.java │ │ ├── Const.java │ │ └── activity │ │ └── MainActivity.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ ├── activity_main.xml │ └── fragment_camera_custom.xml │ ├── menu │ └── main.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # svn 2 | *.svn* 3 | 4 | # built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # files for the dex VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # generated GUI files 15 | */R.java 16 | 17 | # generated folder 18 | bin 19 | gen 20 | 21 | # local 22 | local.properties 23 | proguard.cfg 24 | 25 | # log files 26 | log*.txt 27 | 28 | # archives 29 | *.gz 30 | *.tar 31 | *.zip 32 | 33 | # eclipse 34 | *.metadata 35 | *.settings 36 | 37 | #idea 38 | *.idea 39 | *.iml 40 | out/ 41 | 42 | #gradle 43 | /build 44 | .gradle/ -------------------------------------------------------------------------------- /CameraModule/.gitignore: -------------------------------------------------------------------------------- 1 | # svn 2 | *.svn* 3 | 4 | # built application files 5 | *.apk 6 | *.ap_ 7 | 8 | # files for the dex VM 9 | *.dex 10 | 11 | # Java class files 12 | *.class 13 | 14 | # generated GUI files 15 | */R.java 16 | 17 | # generated folder 18 | bin 19 | gen 20 | 21 | # local 22 | local.properties 23 | proguard.cfg 24 | 25 | # log files 26 | log*.txt 27 | 28 | # archives 29 | *.gz 30 | *.tar 31 | *.zip 32 | 33 | # eclipse 34 | *.metadata 35 | *.settings 36 | 37 | #idea 38 | *.idea 39 | *.iml 40 | out/ 41 | 42 | #gradle 43 | /build 44 | .gradle/ -------------------------------------------------------------------------------- /CameraModule/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | repositories { 4 | mavenCentral() 5 | } 6 | 7 | android { 8 | compileSdkVersion 19 9 | buildToolsVersion '19.1.0' 10 | 11 | defaultConfig { 12 | minSdkVersion 14 13 | targetSdkVersion 19 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | 18 | compileOptions { 19 | sourceCompatibility JavaVersion.VERSION_1_7 20 | targetCompatibility JavaVersion.VERSION_1_7 21 | } 22 | buildTypes { 23 | release { 24 | runProguard false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 26 | } 27 | } 28 | } 29 | 30 | dependencies { 31 | compile 'com.edmodo:cropper:1.0.1' 32 | compile 'com.squareup.picasso:picasso:2.2.0' 33 | compile 'com.jakewharton.timber:timber:2.2.2' 34 | compile fileTree(dir: 'libs', include: ['*.jar']) 35 | } 36 | -------------------------------------------------------------------------------- /CameraModule/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:/androidsdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the ProGuard 5 | # include property in project.properties. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} -------------------------------------------------------------------------------- /CameraModule/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 41 | 42 | 46 | 47 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/squareup/picasso/PicassoTools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.squareup.picasso; 25 | 26 | public class PicassoTools { 27 | 28 | public static void clearCache(Picasso p) { 29 | p.cache.clear(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/CameraConst.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule; 25 | 26 | public final class CameraConst { 27 | 28 | public static final boolean DEBUG = true; 29 | 30 | public static final int COMPRESS_QUALITY = 90; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/ManagerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule; 25 | 26 | import android.content.Context; 27 | 28 | import com.yalantis.cameramodule.interfaces.Initializer; 29 | import com.yalantis.cameramodule.manager.ImageManager; 30 | import com.yalantis.cameramodule.manager.LoggerManager; 31 | import com.yalantis.cameramodule.manager.SharedPrefManager; 32 | 33 | public enum ManagerInitializer implements Initializer { 34 | i; 35 | 36 | @Override 37 | public void init(Context context) { 38 | SharedPrefManager.i.init(context); 39 | LoggerManager.i.init(context); 40 | ImageManager.i.init(context); 41 | } 42 | 43 | @Override 44 | public void clear() { 45 | SharedPrefManager.i.clear(); 46 | LoggerManager.i.clear(); 47 | ImageManager.i.clear(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.activity; 25 | 26 | import android.app.Activity; 27 | import android.content.Context; 28 | import android.os.Bundle; 29 | import android.os.Handler; 30 | import android.os.Message; 31 | import android.view.MenuItem; 32 | import android.view.View; 33 | import android.view.inputmethod.InputMethodManager; 34 | 35 | public abstract class BaseActivity extends Activity { 36 | 37 | protected Handler handler; 38 | 39 | @Override 40 | public void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | handler = new Handler(new Handler.Callback() { 43 | 44 | @Override 45 | public boolean handleMessage(Message msg) { 46 | return BaseActivity.this.handleMessage(msg); 47 | } 48 | }); 49 | } 50 | 51 | protected void hideKeyboard() { 52 | InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 53 | View view = this.getCurrentFocus(); 54 | if (view != null) { 55 | if (inputManager != null) { 56 | inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 57 | } 58 | } 59 | } 60 | 61 | protected boolean handleMessage(Message msg) { 62 | return false; 63 | } 64 | 65 | protected void showActionBar() { 66 | if (getActionBar() != null) { 67 | getActionBar().show(); 68 | } 69 | } 70 | 71 | protected void hideActionBar() { 72 | if (getActionBar() != null) { 73 | getActionBar().hide(); 74 | } 75 | } 76 | 77 | public void showBack() { 78 | getActionBar().setDisplayShowHomeEnabled(false); 79 | getActionBar().setDisplayHomeAsUpEnabled(true); 80 | } 81 | 82 | public void hideBack() { 83 | getActionBar().setDisplayShowHomeEnabled(true); 84 | getActionBar().setDisplayHomeAsUpEnabled(false); 85 | } 86 | 87 | @Override 88 | public boolean onOptionsItemSelected(MenuItem menuItem) { 89 | switch (menuItem.getItemId()) { 90 | case android.R.id.home: 91 | super.onBackPressed(); 92 | return true; 93 | } 94 | return super.onOptionsItemSelected(menuItem); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/activity/BasePhotoActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.activity; 25 | 26 | import android.app.Fragment; 27 | import android.content.Intent; 28 | import android.graphics.Bitmap; 29 | import android.graphics.drawable.Drawable; 30 | import android.os.Bundle; 31 | import android.util.DisplayMetrics; 32 | import android.view.View; 33 | 34 | import com.squareup.picasso.Picasso; 35 | import com.squareup.picasso.Target; 36 | import com.yalantis.cameramodule.R; 37 | import com.yalantis.cameramodule.manager.ImageManager; 38 | 39 | public abstract class BasePhotoActivity extends BaseActivity { 40 | 41 | protected String path; 42 | protected String name; 43 | protected Bitmap bitmap; 44 | 45 | protected View progressBar; 46 | 47 | @Override 48 | public void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | showActionBar(); 51 | showBack(); 52 | setContentView(R.layout.activity_photo); 53 | 54 | if (getIntent().hasExtra(EXTRAS.PATH)) { 55 | path = getIntent().getStringExtra(EXTRAS.PATH); 56 | } else { 57 | throw new RuntimeException("There is no path to image in extras"); 58 | } 59 | if (getIntent().hasExtra(EXTRAS.NAME)) { 60 | name = getIntent().getStringExtra(EXTRAS.NAME); 61 | } else { 62 | throw new RuntimeException("There is no image name in extras"); 63 | } 64 | 65 | progressBar = findViewById(R.id.progress); 66 | 67 | } 68 | 69 | @Override 70 | protected void onResume() { 71 | super.onResume(); 72 | if (bitmap == null || bitmap.isRecycled()) { 73 | loadPhoto(); 74 | } 75 | } 76 | 77 | protected abstract void showPhoto(Bitmap bitmap); 78 | 79 | protected void rotatePhoto(float angle) { 80 | synchronized (bitmap) { 81 | bitmap = ImageManager.i.rotatePhoto(path, angle); 82 | showPhoto(bitmap); 83 | } 84 | setResult(EXTRAS.RESULT_EDITED, setIntentData()); 85 | } 86 | 87 | protected void deletePhoto() { 88 | setResult(EXTRAS.RESULT_DELETED, setIntentData()); 89 | finish(); 90 | } 91 | 92 | protected void loadPhoto() { 93 | DisplayMetrics metrics = new DisplayMetrics(); 94 | getWindowManager().getDefaultDisplay().getMetrics(metrics); 95 | ImageManager.i.loadPhoto(path, metrics.widthPixels, metrics.heightPixels, loadingTarget); 96 | } 97 | 98 | protected void setFragment(Fragment fragment) { 99 | getFragmentManager() 100 | .beginTransaction() 101 | .replace(R.id.fragment_content, fragment) 102 | .commit(); 103 | } 104 | 105 | private Target loadingTarget = new Target() { 106 | 107 | @Override 108 | public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 109 | progressBar.setVisibility(View.GONE); 110 | BasePhotoActivity.this.bitmap = bitmap; 111 | showPhoto(bitmap); 112 | } 113 | 114 | @Override 115 | public void onBitmapFailed(Drawable errorDrawable) { 116 | progressBar.setVisibility(View.GONE); 117 | bitmap = null; 118 | } 119 | 120 | @Override 121 | public void onPrepareLoad(Drawable placeHolderDrawable) { 122 | progressBar.setVisibility(View.VISIBLE); 123 | } 124 | 125 | }; 126 | 127 | protected Intent setIntentData() { 128 | return setIntentData(null); 129 | } 130 | 131 | protected Intent setIntentData(Intent intent) { 132 | if (intent == null) { 133 | intent = new Intent(); 134 | } 135 | intent.putExtra(EXTRAS.PATH, path); 136 | intent.putExtra(EXTRAS.NAME, name); 137 | return intent; 138 | } 139 | 140 | public static final class EXTRAS { 141 | 142 | public static final String PATH = "path"; 143 | 144 | public static final String NAME = "name"; 145 | 146 | public static final String FROM_CAMERA = "from_camera"; 147 | 148 | public static final int REQUEST_PHOTO_EDIT = 7338; 149 | 150 | public static final int RESULT_EDITED = 338; 151 | 152 | public static final int RESULT_DELETED = 3583; 153 | 154 | } 155 | 156 | @Override 157 | public void onBackPressed() { 158 | super.onBackPressed(); 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/activity/CameraActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.activity; 25 | 26 | import android.content.Intent; 27 | import android.media.ExifInterface; 28 | import android.os.Bundle; 29 | import android.os.Environment; 30 | import android.text.TextUtils; 31 | import android.view.KeyEvent; 32 | import android.widget.Toast; 33 | import com.yalantis.cameramodule.CameraConst; 34 | import com.yalantis.cameramodule.R; 35 | import com.yalantis.cameramodule.fragment.CameraFragment; 36 | import com.yalantis.cameramodule.interfaces.*; 37 | import com.yalantis.cameramodule.manager.SharedPrefManager; 38 | import com.yalantis.cameramodule.util.PhotoUtil; 39 | import com.yalantis.cameramodule.util.SavingPhotoTask; 40 | import timber.log.Timber; 41 | 42 | import java.io.IOException; 43 | import java.text.SimpleDateFormat; 44 | import java.util.Date; 45 | 46 | public class CameraActivity extends BaseActivity implements PhotoTakenCallback, PhotoSavedListener, RawPhotoTakenCallback, 47 | CameraParamsChangedListener { 48 | 49 | public static final String PATH = "path"; 50 | public static final String USE_FRONT_CAMERA = "use_front_camera"; 51 | public static final String OPEN_PHOTO_PREVIEW = "open_photo_preview"; 52 | public static final String LAYOUT_ID = "layout_id"; 53 | 54 | private static final String IMG_PREFIX = "IMG_"; 55 | private static final String IMG_POSTFIX = ".jpg"; 56 | private static final String TIME_FORMAT = "yyyyMMdd_HHmmss"; 57 | 58 | private KeyEventsListener keyEventsListener; 59 | private PhotoSavedListener photoSavedListener; 60 | 61 | private String path; 62 | private boolean openPreview; 63 | 64 | private boolean saving; 65 | 66 | @Override 67 | public void onCreate(Bundle savedInstanceState) { 68 | super.onCreate(savedInstanceState); 69 | hideActionBar(); 70 | setContentView(R.layout.activity_with_fragment); 71 | if (TextUtils.isEmpty(path = getIntent().getStringExtra(PATH))) { 72 | path = Environment.getExternalStorageDirectory().getPath(); 73 | } 74 | openPreview = getIntent().getBooleanExtra(OPEN_PHOTO_PREVIEW, SharedPrefManager.i.isOpenPhotoPreview()); 75 | if (openPreview != SharedPrefManager.i.isOpenPhotoPreview()) { 76 | SharedPrefManager.i.setOpenPhotoPreview(openPreview); 77 | } 78 | boolean useFrontCamera = getIntent().getBooleanExtra(USE_FRONT_CAMERA, SharedPrefManager.i.useFrontCamera()); 79 | if (useFrontCamera != SharedPrefManager.i.useFrontCamera()) { 80 | SharedPrefManager.i.setUseFrontCamera(useFrontCamera); 81 | } 82 | init(); 83 | } 84 | 85 | private void init() { 86 | CameraFragment fragment; 87 | int layoutId = getIntent().getIntExtra(LAYOUT_ID, -1); 88 | if (layoutId > 0) { 89 | fragment = CameraFragment.newInstance(layoutId, this, createCameraParams()); 90 | } else { 91 | fragment = CameraFragment.newInstance(this, createCameraParams()); 92 | } 93 | fragment.setParamsChangedListener(this); 94 | keyEventsListener = fragment; 95 | photoSavedListener = fragment; 96 | getFragmentManager() 97 | .beginTransaction() 98 | .replace(R.id.fragment_content, fragment) 99 | .commit(); 100 | } 101 | 102 | private Bundle createCameraParams() { 103 | Bundle bundle = new Bundle(); 104 | 105 | bundle.putInt(CameraFragment.RATIO, SharedPrefManager.i.getCameraRatio()); 106 | bundle.putInt(CameraFragment.FLASH_MODE, SharedPrefManager.i.getCameraFlashMode()); 107 | bundle.putInt(CameraFragment.HDR_MODE, SharedPrefManager.i.isHDR()); 108 | bundle.putInt(CameraFragment.QUALITY, SharedPrefManager.i.getCameraQuality()); 109 | bundle.putInt(CameraFragment.FOCUS_MODE, SharedPrefManager.i.getCameraFocusMode()); 110 | bundle.putBoolean(CameraFragment.FRONT_CAMERA, SharedPrefManager.i.useFrontCamera()); 111 | 112 | return bundle; 113 | } 114 | 115 | private String createName() { 116 | String timeStamp = new SimpleDateFormat(TIME_FORMAT).format(new Date()); 117 | return IMG_PREFIX + timeStamp + IMG_POSTFIX; 118 | } 119 | 120 | @Override 121 | public void photoTaken(byte[] data, int orientation) { 122 | savePhoto(data, createName(), path, orientation); 123 | } 124 | 125 | @Override 126 | public void rawPhotoTaken(byte[] data) { 127 | Timber.d("rawPhotoTaken: data[%1d]", data.length); 128 | } 129 | 130 | private void savePhoto(byte[] data, String name, String path, int orientation) { 131 | saving = true; 132 | new SavingPhotoTask(data, name, path, orientation, this).execute(); 133 | } 134 | 135 | @Override 136 | public void photoSaved(String path, String name) { 137 | saving = false; 138 | Toast.makeText(this, "Photo " + name + " saved", Toast.LENGTH_SHORT).show(); 139 | Timber.d("Photo " + name + " saved"); 140 | if (CameraConst.DEBUG) { 141 | printExifOrientation(path); 142 | } 143 | if (openPreview) { 144 | openPreview(path, name); 145 | } 146 | if (photoSavedListener != null) { 147 | photoSavedListener.photoSaved(path, name); 148 | } 149 | } 150 | 151 | private void openPreview(String path, String name) { 152 | Intent intent = new Intent(this, PhotoPreviewActivity.class); 153 | intent.putExtra(BasePhotoActivity.EXTRAS.PATH, path); 154 | intent.putExtra(BasePhotoActivity.EXTRAS.NAME, name); 155 | intent.putExtra(BasePhotoActivity.EXTRAS.FROM_CAMERA, true); 156 | startActivityForResult(intent, BasePhotoActivity.EXTRAS.REQUEST_PHOTO_EDIT); 157 | } 158 | 159 | @Override 160 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 161 | super.onActivityResult(requestCode, resultCode, data); 162 | if (requestCode == BasePhotoActivity.EXTRAS.REQUEST_PHOTO_EDIT) { 163 | switch (resultCode) { 164 | case BasePhotoActivity.EXTRAS.RESULT_DELETED: 165 | String path = data.getStringExtra(BasePhotoActivity.EXTRAS.PATH); 166 | PhotoUtil.deletePhoto(path); 167 | break; 168 | } 169 | } 170 | } 171 | 172 | private void printExifOrientation(String path) { 173 | try { 174 | ExifInterface exif = new ExifInterface(path); 175 | int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 176 | Timber.d("Orientation: " + orientation); 177 | } catch (IOException e) { 178 | Timber.e(e, e.getMessage()); 179 | } 180 | } 181 | 182 | @Override 183 | public boolean onKeyDown(int keyCode, KeyEvent event) { 184 | switch (keyCode) { 185 | case KeyEvent.KEYCODE_VOLUME_UP: 186 | keyEventsListener.zoomIn(); 187 | return true; 188 | case KeyEvent.KEYCODE_VOLUME_DOWN: 189 | keyEventsListener.zoomOut(); 190 | return true; 191 | case KeyEvent.KEYCODE_BACK: 192 | onBackPressed(); 193 | return true; 194 | case KeyEvent.KEYCODE_CAMERA: 195 | keyEventsListener.takePhoto(); 196 | return true; 197 | } 198 | return false; 199 | } 200 | 201 | @Override 202 | public void onQualityChanged(int id) { 203 | SharedPrefManager.i.setCameraQuality(id); 204 | } 205 | 206 | @Override 207 | public void onRatioChanged(int id) { 208 | SharedPrefManager.i.setCameraRatio(id); 209 | } 210 | 211 | @Override 212 | public void onFlashModeChanged(int id) { 213 | SharedPrefManager.i.setCameraFlashMode(id); 214 | } 215 | 216 | @Override 217 | public void onHDRChanged(int id) { 218 | SharedPrefManager.i.setHDRMode(id); 219 | } 220 | 221 | @Override 222 | public void onFocusModeChanged(int id) { 223 | SharedPrefManager.i.setCameraFocusMode(id); 224 | } 225 | 226 | @Override 227 | public void onBackPressed() { 228 | if (!saving) { 229 | super.onBackPressed(); 230 | } 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/activity/PhotoCropActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.activity; 25 | 26 | import android.graphics.Bitmap; 27 | import android.graphics.RectF; 28 | import android.view.Menu; 29 | import android.view.MenuInflater; 30 | import android.view.MenuItem; 31 | 32 | import com.yalantis.cameramodule.R; 33 | import com.yalantis.cameramodule.fragment.PhotoCropFragment; 34 | import com.yalantis.cameramodule.interfaces.PhotoCroppedCallback; 35 | import com.yalantis.cameramodule.interfaces.PhotoSavedListener; 36 | import com.yalantis.cameramodule.manager.ImageManager; 37 | 38 | public class PhotoCropActivity extends BasePhotoActivity implements PhotoCroppedCallback { 39 | 40 | private PhotoCropFragment cropFragment; 41 | 42 | @Override 43 | public boolean onCreateOptionsMenu(Menu menu) { 44 | MenuInflater inflater = getMenuInflater(); 45 | inflater.inflate(R.menu.photo_crop_options, menu); 46 | return super.onCreateOptionsMenu(menu); 47 | } 48 | 49 | public void apply(MenuItem ite) { 50 | cropFragment.applyCrop(); 51 | } 52 | 53 | public void cancel(MenuItem ite) { 54 | finish(); 55 | } 56 | 57 | @Override 58 | protected void showPhoto(Bitmap bitmap) { 59 | if (cropFragment == null) { 60 | cropFragment = PhotoCropFragment.newInstance(bitmap); 61 | setFragment(cropFragment); 62 | } else { 63 | cropFragment.setBitmap(bitmap); 64 | } 65 | } 66 | 67 | @Override 68 | public void onPhotoCropped(int width, int height, Bitmap croppedBitmap, RectF cropRect) { 69 | ImageManager.i.cropBitmap(path, width, height, croppedBitmap, cropRect, new PhotoSavedListener() { 70 | 71 | @Override 72 | public void photoSaved(String path, String name) { 73 | setResult(EXTRAS.RESULT_EDITED, setIntentData()); 74 | finish(); 75 | } 76 | }); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/activity/PhotoPreviewActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.activity; 25 | 26 | import android.content.Intent; 27 | import android.graphics.Bitmap; 28 | import android.os.Bundle; 29 | import android.view.Menu; 30 | import android.view.MenuInflater; 31 | import android.view.MenuItem; 32 | 33 | import com.yalantis.cameramodule.R; 34 | import com.yalantis.cameramodule.fragment.PhotoPreviewFragment; 35 | 36 | public class PhotoPreviewActivity extends BasePhotoActivity { 37 | 38 | private PhotoPreviewFragment previewFragment; 39 | 40 | @Override 41 | public void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | if (getIntent().getBooleanExtra(EXTRAS.FROM_CAMERA, false)) { 44 | setTitle(R.string.lbl_take_another); 45 | } 46 | } 47 | 48 | @Override 49 | public boolean onCreateOptionsMenu(Menu menu) { 50 | MenuInflater inflater = getMenuInflater(); 51 | inflater.inflate(R.menu.photo_preview_options, menu); 52 | return super.onCreateOptionsMenu(menu); 53 | } 54 | 55 | public void deletePhoto(MenuItem item) { 56 | deletePhoto(); 57 | } 58 | 59 | public void rotateLeft(MenuItem item) { 60 | rotatePhoto(-90); 61 | } 62 | 63 | public void rotateRight(MenuItem item) { 64 | rotatePhoto(90); 65 | } 66 | 67 | public void openPhotoCropper(MenuItem item) { 68 | Intent intent = new Intent(this, PhotoCropActivity.class); 69 | startActivityForResult(setIntentData(intent), EXTRAS.REQUEST_PHOTO_EDIT); 70 | } 71 | 72 | @Override 73 | protected void showPhoto(Bitmap bitmap) { 74 | if (previewFragment == null) { 75 | previewFragment = PhotoPreviewFragment.newInstance(bitmap); 76 | setFragment(previewFragment); 77 | } else { 78 | previewFragment.setBitmap(bitmap); 79 | } 80 | } 81 | 82 | @Override 83 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 84 | super.onActivityResult(requestCode, resultCode, data); 85 | if (requestCode == EXTRAS.REQUEST_PHOTO_EDIT) { 86 | if (resultCode == EXTRAS.RESULT_EDITED) { 87 | setResult(EXTRAS.RESULT_EDITED, setIntentData()); 88 | loadPhoto(); 89 | } 90 | } 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/adapters/BaseListAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.adapters; 25 | 26 | import java.util.List; 27 | 28 | import android.content.Context; 29 | import android.content.res.Resources; 30 | import android.view.LayoutInflater; 31 | import android.view.View; 32 | import android.widget.BaseAdapter; 33 | 34 | public abstract class BaseListAdapter extends BaseAdapter { 35 | 36 | private Context mContext; 37 | private List mList; 38 | private int mLayoutId; 39 | 40 | public BaseListAdapter(Context context, List list, int layout) { 41 | mContext = context; 42 | setList(list); 43 | mLayoutId = layout; 44 | } 45 | 46 | @Override 47 | public int getCount() { 48 | if (mList != null) { 49 | return mList.size(); 50 | } 51 | return 0; 52 | } 53 | 54 | public void addItems(List items) { 55 | mList.addAll(items); 56 | notifyDataSetChanged(); 57 | } 58 | 59 | public void addItem(T type) { 60 | mList.add(type); 61 | notifyDataSetChanged(); 62 | } 63 | 64 | @Override 65 | public T getItem(int position) { 66 | return position >= 0 && position < mList.size() ? mList.get(position) : null; 67 | } 68 | 69 | @Override 70 | public long getItemId(int position) { 71 | return position; 72 | } 73 | 74 | public Context getContext() { 75 | return mContext; 76 | } 77 | 78 | public Resources getResources() { 79 | return getContext().getResources(); 80 | } 81 | 82 | public List getList() { 83 | return mList; 84 | } 85 | 86 | public void setList(List list) { 87 | this.mList = list; 88 | } 89 | 90 | public void removeItem(int position) { 91 | mList.remove(position); 92 | notifyDataSetChanged(); 93 | } 94 | 95 | public View getLayout() { 96 | return getInflater().inflate(getLayoutId(), null); 97 | } 98 | 99 | public int getLayoutId() { 100 | return mLayoutId; 101 | } 102 | 103 | public LayoutInflater getInflater() { 104 | return LayoutInflater.from(mContext); 105 | } 106 | 107 | public void clear() { 108 | mList.clear(); 109 | notifyDataSetChanged(); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/adapters/ObjectToStringAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.adapters; 25 | 26 | import java.util.List; 27 | 28 | import android.content.Context; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | import android.widget.TextView; 32 | 33 | import com.yalantis.cameramodule.R; 34 | 35 | public class ObjectToStringAdapter extends BaseListAdapter { 36 | 37 | public ObjectToStringAdapter(Context context, List list) { 38 | super(context, list, R.layout.object_to_string_list_item); 39 | } 40 | 41 | @Override 42 | public View getView(int position, View convertView, ViewGroup parent) { 43 | return createView(position, convertView, false); 44 | } 45 | 46 | @Override 47 | public View getDropDownView(int position, View convertView, ViewGroup parent) { 48 | return createView(position, convertView, true); 49 | } 50 | 51 | private View createView(int position, View convertView, boolean dropDown) { 52 | ViewHolder holder; 53 | 54 | if (convertView == null) { 55 | if (dropDown) { 56 | convertView = getDropDownLayout(); 57 | } else { 58 | convertView = getLayout(); 59 | } 60 | holder = new ViewHolder(); 61 | holder.text = (TextView) convertView.findViewById(R.id.title); 62 | 63 | convertView.setTag(holder); 64 | } else { 65 | holder = (ViewHolder) convertView.getTag(); 66 | } 67 | 68 | T item = getItem(position); 69 | if (item != null) { 70 | holder.text.setText(item.toString()); 71 | } 72 | 73 | return convertView; 74 | } 75 | 76 | public View getDropDownLayout() { 77 | return getInflater().inflate(R.layout.object_to_string_dropdown_list_item, null); 78 | } 79 | 80 | class ViewHolder { 81 | 82 | TextView text; 83 | 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/control/PreviewImageView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.control; 25 | 26 | import android.content.Context; 27 | import android.util.AttributeSet; 28 | import android.widget.ImageView; 29 | 30 | public class PreviewImageView extends ImageView { 31 | 32 | public PreviewImageView(Context context) { 33 | super(context); 34 | } 35 | 36 | public PreviewImageView(Context context, AttributeSet attrs) { 37 | super(context, attrs); 38 | } 39 | 40 | @Override 41 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 42 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 43 | setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/fragment/BaseDialogFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.fragment; 25 | 26 | import android.app.Activity; 27 | import android.app.Dialog; 28 | import android.app.DialogFragment; 29 | import android.app.FragmentManager; 30 | import android.graphics.drawable.ColorDrawable; 31 | import android.os.Bundle; 32 | import android.view.Window; 33 | 34 | public abstract class BaseDialogFragment extends DialogFragment { 35 | 36 | protected Activity activity; 37 | 38 | @Override 39 | public Dialog onCreateDialog(Bundle savedInstanceState) { 40 | Dialog dialog = super.onCreateDialog(savedInstanceState); 41 | dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 42 | dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0)); 43 | return dialog; 44 | } 45 | 46 | @Override 47 | public void onAttach(Activity activity) { 48 | super.onAttach(activity); 49 | this.activity = activity; 50 | } 51 | 52 | public abstract String getFragmentTag(); 53 | 54 | public void show(FragmentManager manager) { 55 | super.show(manager, getFragmentTag()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.fragment; 25 | 26 | import android.app.Activity; 27 | import android.app.Fragment; 28 | import android.os.Bundle; 29 | import android.os.Handler; 30 | 31 | public class BaseFragment extends Fragment { 32 | 33 | private Handler handler; 34 | protected Activity activity; 35 | 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | handler = new Handler(); 40 | } 41 | 42 | @Override 43 | public void onAttach(Activity activity) { 44 | super.onAttach(activity); 45 | this.activity = activity; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/fragment/CameraSettingsDialogFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.fragment; 25 | 26 | import android.os.Bundle; 27 | import android.view.LayoutInflater; 28 | import android.view.View; 29 | import android.view.ViewGroup; 30 | import android.widget.AdapterView; 31 | import android.widget.CompoundButton; 32 | import android.widget.Spinner; 33 | import android.widget.Switch; 34 | import com.yalantis.cameramodule.R; 35 | import com.yalantis.cameramodule.adapters.ObjectToStringAdapter; 36 | import com.yalantis.cameramodule.interfaces.CameraParamsChangedListener; 37 | import com.yalantis.cameramodule.model.FocusMode; 38 | import com.yalantis.cameramodule.model.HDRMode; 39 | import com.yalantis.cameramodule.model.Quality; 40 | import com.yalantis.cameramodule.model.Ratio; 41 | 42 | import java.util.Arrays; 43 | import java.util.List; 44 | 45 | public class CameraSettingsDialogFragment extends BaseDialogFragment { 46 | 47 | public static final String TAG = CameraSettingsDialogFragment.class.getSimpleName(); 48 | 49 | private CameraParamsChangedListener paramsChangedListener; 50 | 51 | private Quality quality; 52 | private Ratio ratio; 53 | private FocusMode focusMode; 54 | private HDRMode hdrMode; 55 | private List ratios = Arrays.asList(Ratio.values()); 56 | private List qualities = Arrays.asList(Quality.values()); 57 | private List focusModes = Arrays.asList(FocusMode.values()); 58 | 59 | public static CameraSettingsDialogFragment newInstance(Bundle bundle, CameraParamsChangedListener listener) { 60 | CameraSettingsDialogFragment fragment = new CameraSettingsDialogFragment(); 61 | fragment.setArguments(bundle); 62 | fragment.paramsChangedListener = listener; 63 | return fragment; 64 | } 65 | 66 | @Override 67 | public void onCreate(Bundle savedInstanceState) { 68 | super.onCreate(savedInstanceState); 69 | expandParams(getArguments()); 70 | } 71 | 72 | private void expandParams(Bundle params) { 73 | if (params == null) { 74 | params = new Bundle(); 75 | } 76 | int id = 0; 77 | if (params.containsKey(CameraFragment.QUALITY)) { 78 | id = params.getInt(CameraFragment.QUALITY, 0); 79 | } 80 | quality = Quality.getQualityById(id); 81 | id = 0; 82 | if (params.containsKey(CameraFragment.RATIO)) { 83 | id = params.getInt(CameraFragment.RATIO, 0); 84 | } 85 | ratio = Ratio.getRatioById(id); 86 | id = 0; 87 | if (params.containsKey(CameraFragment.FOCUS_MODE)) { 88 | id = params.getInt(CameraFragment.FOCUS_MODE); 89 | } 90 | focusMode = FocusMode.getFocusModeById(id); 91 | id = 0; 92 | if (params.containsKey(CameraFragment.HDR_MODE)) { 93 | id = params.getInt(CameraFragment.HDR_MODE); 94 | } 95 | hdrMode = HDRMode.getHDRModeById(id); 96 | } 97 | 98 | @Override 99 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 100 | View view = inflater.inflate(R.layout.dialog_camera_params, container, false); 101 | 102 | Spinner ratioSwitcher = (Spinner) view.findViewById(R.id.ratios); 103 | ratioSwitcher.setAdapter(new ObjectToStringAdapter<>(activity, ratios)); 104 | ratioSwitcher.setSelection(ratios.indexOf(ratio)); 105 | ratioSwitcher.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 106 | 107 | @Override 108 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 109 | if (ratio == ratios.get(position)) { 110 | return; 111 | } 112 | ratio = ratios.get(position); 113 | onRatioChanged(ratio.getId()); 114 | } 115 | 116 | @Override 117 | public void onNothingSelected(AdapterView parent) { 118 | } 119 | }); 120 | 121 | Spinner qualitySwitcher = (Spinner) view.findViewById(R.id.qualities); 122 | qualitySwitcher.setAdapter(new ObjectToStringAdapter<>(activity, qualities)); 123 | qualitySwitcher.setSelection(qualities.indexOf(quality)); 124 | qualitySwitcher.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 125 | 126 | @Override 127 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 128 | if (quality == qualities.get(position)) { 129 | return; 130 | } 131 | quality = qualities.get(position); 132 | onQualityChanged(quality.getId()); 133 | } 134 | 135 | @Override 136 | public void onNothingSelected(AdapterView parent) { 137 | } 138 | }); 139 | 140 | Spinner focusSwitcher = (Spinner) view.findViewById(R.id.focus_modes); 141 | focusSwitcher.setAdapter(new ObjectToStringAdapter<>(activity, focusModes)); 142 | focusSwitcher.setSelection(focusModes.indexOf(focusMode)); 143 | focusSwitcher.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 144 | 145 | @Override 146 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 147 | if (focusMode == focusModes.get(position)) { 148 | return; 149 | } 150 | focusMode = focusModes.get(position); 151 | onFocusModeChanged(focusMode.getId()); 152 | } 153 | 154 | @Override 155 | public void onNothingSelected(AdapterView parent) { 156 | } 157 | }); 158 | if (hdrMode == HDRMode.NONE) { 159 | view.findViewById(R.id.relativeHdr).setVisibility(View.GONE); 160 | } else { 161 | view.findViewById(R.id.relativeHdr).setVisibility(View.VISIBLE); 162 | Switch hdrSwitch = (Switch) view.findViewById(R.id.switchHDR); 163 | hdrSwitch.setChecked(hdrMode == HDRMode.ON); 164 | hdrSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 165 | 166 | @Override 167 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 168 | onHDRChanged(isChecked ? HDRMode.ON.getId() : HDRMode.OFF.getId()); 169 | } 170 | }); 171 | } 172 | 173 | view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() { 174 | 175 | @Override 176 | public void onClick(View v) { 177 | dismiss(); 178 | } 179 | 180 | }); 181 | 182 | return view; 183 | } 184 | 185 | public void onQualityChanged(int id) { 186 | if (paramsChangedListener != null) { 187 | paramsChangedListener.onQualityChanged(id); 188 | } 189 | } 190 | 191 | public void onHDRChanged(int id) { 192 | if (paramsChangedListener != null) { 193 | paramsChangedListener.onHDRChanged(id); 194 | } 195 | } 196 | 197 | public void onRatioChanged(int id) { 198 | if (paramsChangedListener != null) { 199 | paramsChangedListener.onRatioChanged(id); 200 | } 201 | } 202 | 203 | public void onFocusModeChanged(int id) { 204 | if (paramsChangedListener != null) { 205 | paramsChangedListener.onFocusModeChanged(id); 206 | } 207 | } 208 | 209 | @Override 210 | public String getFragmentTag() { 211 | return TAG; 212 | } 213 | 214 | } 215 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/fragment/PhotoCropFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.fragment; 25 | 26 | import android.app.Activity; 27 | import android.graphics.Bitmap; 28 | import android.os.Bundle; 29 | import android.view.LayoutInflater; 30 | import android.view.View; 31 | import android.view.ViewGroup; 32 | 33 | import com.edmodo.cropper.CropImageView; 34 | import com.yalantis.cameramodule.R; 35 | import com.yalantis.cameramodule.interfaces.PhotoCroppedCallback; 36 | 37 | public class PhotoCropFragment extends BaseFragment { 38 | 39 | private Bitmap bitmap; 40 | private CropImageView cropView; 41 | 42 | private PhotoCroppedCallback callback; 43 | 44 | public static PhotoCropFragment newInstance(Bitmap bitmap) { 45 | PhotoCropFragment fragment = new PhotoCropFragment(); 46 | fragment.bitmap = bitmap; 47 | 48 | return fragment; 49 | } 50 | 51 | @Override 52 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 53 | return inflater.inflate(R.layout.fragment_photo_crop, container, false); 54 | } 55 | 56 | @Override 57 | public void onViewCreated(final View view, Bundle savedInstanceState) { 58 | super.onViewCreated(view, savedInstanceState); 59 | 60 | cropView = (CropImageView) view.findViewById(R.id.photo); 61 | cropView.setImageBitmap(bitmap); 62 | } 63 | 64 | @Override 65 | public void onAttach(Activity activity) { 66 | super.onAttach(activity); 67 | if (activity instanceof PhotoCroppedCallback) { 68 | callback = (PhotoCroppedCallback) activity; 69 | } else { 70 | throw new RuntimeException(activity.getClass().getName() + " must implement " + PhotoCroppedCallback.class.getName()); 71 | } 72 | } 73 | 74 | public void setBitmap(Bitmap bitmap) { 75 | this.bitmap = bitmap; 76 | cropView.setImageBitmap(bitmap); 77 | } 78 | 79 | public void applyCrop() { 80 | callback.onPhotoCropped(bitmap.getWidth(), bitmap.getHeight(), cropView.getCroppedImage(), cropView.getActualCropRect()); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/fragment/PhotoPreviewFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.fragment; 25 | 26 | import android.graphics.Bitmap; 27 | import android.os.Bundle; 28 | import android.view.LayoutInflater; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | 32 | import com.yalantis.cameramodule.R; 33 | import com.yalantis.cameramodule.control.PinchImageView; 34 | 35 | public class PhotoPreviewFragment extends BaseFragment { 36 | 37 | private Bitmap bitmap; 38 | private PinchImageView imageView; 39 | 40 | public static PhotoPreviewFragment newInstance(Bitmap bitmap) { 41 | PhotoPreviewFragment fragment = new PhotoPreviewFragment(); 42 | fragment.bitmap = bitmap; 43 | 44 | return fragment; 45 | } 46 | 47 | @Override 48 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 49 | return inflater.inflate(R.layout.fragment_photo_preview, container, false); 50 | } 51 | 52 | @Override 53 | public void onViewCreated(final View view, Bundle savedInstanceState) { 54 | super.onViewCreated(view, savedInstanceState); 55 | 56 | imageView = (PinchImageView) view.findViewById(R.id.photo); 57 | 58 | if (bitmap != null && !bitmap.isRecycled()) { 59 | imageView.setImageBitmap(bitmap); 60 | } else { 61 | imageView.setImageResource(R.drawable.no_image); 62 | } 63 | } 64 | 65 | public void setBitmap(Bitmap bitmap) { 66 | this.bitmap = bitmap; 67 | imageView.setImageBitmap(bitmap); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/CameraParamsChangedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | public interface CameraParamsChangedListener { 27 | 28 | public void onQualityChanged(int id); 29 | 30 | public void onRatioChanged(int id); 31 | 32 | public void onFlashModeChanged(int id); 33 | 34 | public void onHDRChanged(int id); 35 | 36 | public void onFocusModeChanged(int id); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/FocusCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | import android.hardware.Camera; 27 | 28 | public interface FocusCallback { 29 | 30 | public void onFocused(Camera camera); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/Initializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | import android.content.Context; 27 | 28 | public interface Initializer { 29 | 30 | public void init(Context context); 31 | 32 | public void clear(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/KeyEventsListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | public interface KeyEventsListener { 27 | 28 | public void zoomIn(); 29 | 30 | public void zoomOut(); 31 | 32 | public void takePhoto(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/PhotoActionsCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | public interface PhotoActionsCallback { 27 | 28 | public void onOpenPhotoPreview(String path, String name); 29 | 30 | public void onAddNote(int zpid, String name); 31 | 32 | public void onRetake(String name); 33 | 34 | public void onDeletePhoto(String name); 35 | 36 | public void onDeleteHomePhotos(int zpid); 37 | 38 | public void onDeleteAddressPhotos(String address); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/PhotoCroppedCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | import android.graphics.Bitmap; 27 | import android.graphics.RectF; 28 | 29 | public interface PhotoCroppedCallback { 30 | 31 | /** 32 | * @param width 33 | * width before crop 34 | * @param height 35 | * height before crop 36 | * @param croppedBitmap 37 | * cropped bitmap 38 | * @param cropRect 39 | * cropping rectangle 40 | */ 41 | public void onPhotoCropped(int width, int height, Bitmap croppedBitmap, RectF cropRect); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/PhotoSavedListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | public interface PhotoSavedListener { 27 | 28 | public void photoSaved(String path, String name); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/PhotoTakenCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | public interface PhotoTakenCallback { 27 | 28 | public void photoTaken(byte[] data, int orientation); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/RawPhotoTakenCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | public interface RawPhotoTakenCallback { 27 | 28 | public void rawPhotoTaken(byte[] data); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/interfaces/StorageCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.interfaces; 25 | 26 | import android.graphics.Bitmap; 27 | 28 | import com.yalantis.cameramodule.util.ManagedTarget; 29 | 30 | public interface StorageCallback { 31 | 32 | public void setBitmap(String path, Bitmap bitmap); 33 | 34 | public void addTarget(ManagedTarget target); 35 | 36 | public void removeTarget(ManagedTarget target); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/manager/ImageManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.manager; 25 | 26 | import java.io.File; 27 | import java.lang.ref.WeakReference; 28 | import java.util.HashMap; 29 | import java.util.HashSet; 30 | import java.util.Map; 31 | 32 | import android.content.Context; 33 | import android.graphics.Bitmap; 34 | import android.graphics.Matrix; 35 | import android.graphics.RectF; 36 | import android.text.TextUtils; 37 | 38 | import com.squareup.picasso.Picasso; 39 | import com.squareup.picasso.PicassoTools; 40 | import com.squareup.picasso.Target; 41 | import com.yalantis.cameramodule.interfaces.Initializer; 42 | import com.yalantis.cameramodule.interfaces.PhotoSavedListener; 43 | import com.yalantis.cameramodule.interfaces.StorageCallback; 44 | import com.yalantis.cameramodule.util.CropPhotoTask; 45 | import com.yalantis.cameramodule.util.ManagedTarget; 46 | import com.yalantis.cameramodule.util.RotatePhotoTask; 47 | import com.yalantis.cameramodule.util.ScaleTransformation; 48 | 49 | public enum ImageManager implements Initializer, StorageCallback { 50 | i; 51 | 52 | private Context context; 53 | private Picasso picasso; 54 | 55 | private HashSet targets; 56 | private Map> bitmapMap; 57 | 58 | @Override 59 | public void init(Context context) { 60 | this.context = context; 61 | this.picasso = Picasso.with(context); 62 | bitmapMap = new HashMap<>(); 63 | targets = new HashSet<>(); 64 | } 65 | 66 | public void loadPhoto(String path, int width, int height, Target target) { 67 | File photo = !TextUtils.isEmpty(path) ? new File(path) : null; 68 | if (path == null) { 69 | target.onBitmapFailed(null); 70 | } 71 | Bitmap bitmap = getBitmap(path); 72 | if (bitmap != null && !bitmap.isRecycled()) { 73 | target.onBitmapLoaded(bitmap, Picasso.LoadedFrom.MEMORY); 74 | } else { 75 | ManagedTarget managedTarget = new ManagedTarget(target, path, this); 76 | Picasso.with(context) 77 | .load(photo) 78 | .skipMemoryCache() 79 | .config(Bitmap.Config.ARGB_8888) 80 | .transform(new ScaleTransformation(width, height)) 81 | .into(managedTarget); 82 | } 83 | } 84 | 85 | public void cropBitmap(String path, int width, int height, Bitmap croppedBitmap, RectF rect, PhotoSavedListener callback) { 86 | setBitmap(path, croppedBitmap); 87 | new CropPhotoTask(path, width, height, rect, callback).execute(); 88 | } 89 | 90 | public Bitmap rotatePhoto(String path, float angle) { 91 | Bitmap bitmap = getBitmap(path); 92 | if (bitmap != null && !bitmap.isRecycled()) { 93 | Matrix matrix = new Matrix(); 94 | matrix.postRotate(angle); 95 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 96 | } 97 | setBitmap(path, bitmap); 98 | new RotatePhotoTask(path, angle, null).execute(); 99 | 100 | return bitmap; 101 | } 102 | 103 | private Bitmap getBitmap(String path) { 104 | return bitmapMap.get(path) != null ? bitmapMap.get(path).get() : null; 105 | } 106 | 107 | @Override 108 | public void clear() { 109 | synchronized (bitmapMap) { 110 | for (WeakReference reference : bitmapMap.values()) { 111 | if (reference != null) { 112 | Bitmap bitmap = reference.get(); 113 | if (bitmap != null && !bitmap.isRecycled()) { 114 | bitmap.recycle(); 115 | } 116 | } 117 | } 118 | bitmapMap.clear(); 119 | } 120 | PicassoTools.clearCache(picasso); 121 | } 122 | 123 | @Override 124 | public void setBitmap(String path, Bitmap bitmap) { 125 | bitmapMap.put(path, new WeakReference<>(bitmap)); 126 | } 127 | 128 | @Override 129 | public void addTarget(ManagedTarget target) { 130 | removeTarget(target); 131 | targets.add(target); 132 | } 133 | 134 | @Override 135 | public void removeTarget(ManagedTarget target) { 136 | if (targets.contains(target)) { 137 | targets.remove(target); 138 | } 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/manager/LoggerManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.manager; 25 | 26 | import timber.log.Timber; 27 | import android.content.Context; 28 | 29 | import com.yalantis.cameramodule.CameraConst; 30 | import com.yalantis.cameramodule.interfaces.Initializer; 31 | 32 | public enum LoggerManager implements Initializer { 33 | i; 34 | 35 | private Context context; 36 | 37 | @Override 38 | public void init(Context context) { 39 | this.context = context; 40 | if (CameraConst.DEBUG) { 41 | Timber.plant(new Timber.DebugTree()); 42 | } else { 43 | Timber.plant(new CrashReportingTree()); 44 | } 45 | } 46 | 47 | /** A tree which logs important information for crash reporting. */ 48 | private static class CrashReportingTree extends Timber.DebugTree { 49 | 50 | @Override 51 | public void d(String message, Object... args) { 52 | } 53 | 54 | @Override 55 | public void d(Throwable t, String message, Object... args) { 56 | } 57 | 58 | @Override 59 | public void i(String message, Object... args) { 60 | } 61 | 62 | @Override 63 | public void i(Throwable t, String message, Object... args) { 64 | } 65 | 66 | @Override 67 | public void w(String message, Object... args) { 68 | } 69 | 70 | @Override 71 | public void w(Throwable t, String message, Object... args) { 72 | } 73 | 74 | @Override 75 | public void e(String message, Object... args) { 76 | super.e(message, args); 77 | } 78 | 79 | @Override 80 | public void e(Throwable t, String message, Object... args) { 81 | super.e(t, message, args); 82 | } 83 | } 84 | 85 | @Override 86 | public void clear() { 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/manager/SharedPrefManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.manager; 25 | 26 | import java.util.HashSet; 27 | import java.util.Set; 28 | 29 | import android.content.Context; 30 | import android.content.SharedPreferences; 31 | 32 | import com.yalantis.cameramodule.interfaces.Initializer; 33 | import com.yalantis.cameramodule.model.CachedValue; 34 | 35 | public enum SharedPrefManager implements Initializer { 36 | i; 37 | 38 | private static final String NAME = "sharedPrefs"; 39 | 40 | public static final String OPEN_PHOTO_PREVIEW = "open_photo_preview"; 41 | public static final String CAMERA_RATIO = "camera_ratio"; 42 | public static final String CAMERA_QUALITY = "camera_quality"; 43 | public static final String CAMERA_FLASH_MODE = "camera_flash_mode"; 44 | public static final String CAMERA_HDR_MODE = "camera_hdr_mode"; 45 | public static final String CAMERA_FOCUS_MODE = "camera_focus_mode"; 46 | public static final String USE_FRONT_CAMERA = "use_front_camera"; 47 | 48 | private static SharedPreferences sp; 49 | 50 | private Set cachedValues; 51 | 52 | private CachedValue openPhotoPreview; 53 | private CachedValue cameraRatio; 54 | private CachedValue cameraQuality; 55 | private CachedValue cameraFlashMode; 56 | private CachedValue isCameraHDRMode; 57 | private CachedValue cameraFocusMode; 58 | private CachedValue useFrontCamera; 59 | 60 | @Override 61 | public void init(Context context) { 62 | sp = context.getSharedPreferences(NAME, Context.MODE_PRIVATE); 63 | CachedValue.initialize(sp); 64 | cachedValues = new HashSet<>(); 65 | cachedValues.add(openPhotoPreview = new CachedValue<>(OPEN_PHOTO_PREVIEW, true, Boolean.class)); 66 | cachedValues.add(isCameraHDRMode = new CachedValue<>(CAMERA_HDR_MODE, 0, Integer.class)); 67 | cachedValues.add(cameraRatio = new CachedValue<>(CAMERA_RATIO, 0, Integer.class)); 68 | cachedValues.add(cameraQuality = new CachedValue<>(CAMERA_QUALITY, 0, Integer.class)); 69 | cachedValues.add(cameraFlashMode = new CachedValue<>(CAMERA_FLASH_MODE, 0, Integer.class)); 70 | cachedValues.add(cameraFocusMode = new CachedValue<>(CAMERA_FOCUS_MODE, 0, Integer.class)); 71 | cachedValues.add(useFrontCamera = new CachedValue<>(USE_FRONT_CAMERA, false, Boolean.class)); 72 | } 73 | 74 | public void setHDRMode(int isHDR) { 75 | this.isCameraHDRMode.setValue(isHDR); 76 | } 77 | 78 | public int isHDR() { 79 | return isCameraHDRMode.getValue(); 80 | } 81 | 82 | public boolean isOpenPhotoPreview() { 83 | return openPhotoPreview.getValue(); 84 | } 85 | 86 | public void setOpenPhotoPreview(boolean enabled) { 87 | this.openPhotoPreview.setValue(enabled); 88 | } 89 | 90 | public int getCameraRatio() { 91 | return cameraRatio.getValue(); 92 | } 93 | 94 | public void setCameraRatio(int cameraRatio) { 95 | this.cameraRatio.setValue(cameraRatio); 96 | } 97 | 98 | public int getCameraQuality() { 99 | return cameraQuality.getValue(); 100 | } 101 | 102 | public void setCameraQuality(int cameraQuality) { 103 | this.cameraQuality.setValue(cameraQuality); 104 | } 105 | 106 | public int getCameraFlashMode() { 107 | return cameraFlashMode.getValue(); 108 | } 109 | 110 | public void setCameraFlashMode(int cameraFlashMode) { 111 | this.cameraFlashMode.setValue(cameraFlashMode); 112 | } 113 | 114 | public int getCameraFocusMode() { 115 | return cameraFocusMode.getValue(); 116 | } 117 | 118 | public void setCameraFocusMode(int cameraFocusMode) { 119 | this.cameraFocusMode.setValue(cameraFocusMode); 120 | } 121 | 122 | public boolean useFrontCamera() { 123 | return useFrontCamera.getValue(); 124 | } 125 | 126 | public void setUseFrontCamera(boolean frontCamera) { 127 | this.useFrontCamera.setValue(frontCamera); 128 | } 129 | 130 | @Override 131 | public void clear() { 132 | for (CachedValue value : cachedValues) { 133 | value.clear(); 134 | } 135 | sp.edit().clear().commit(); 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/CachedValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | import android.content.SharedPreferences; 27 | 28 | public class CachedValue { 29 | 30 | private static SharedPreferences sharedPref; 31 | 32 | private SharedPreferences sp; 33 | 34 | private T value; 35 | private T defValue; 36 | private Class type; 37 | private String name; 38 | private boolean loaded = false; 39 | 40 | public CachedValue(String name, Class type) { 41 | this(name, null, null, type); 42 | } 43 | 44 | public CachedValue(String name, T defValue, Class type) { 45 | this(name, null, defValue, type); 46 | } 47 | 48 | public CachedValue(String name, T value, T defValue, Class type) { 49 | this.sp = sharedPref; 50 | this.name = name; 51 | this.type = type; 52 | this.loaded = value != null; 53 | this.value = value; 54 | this.defValue = defValue; 55 | } 56 | 57 | public void setValue(T value) { 58 | loaded = true; 59 | write(this.value = value); 60 | } 61 | 62 | public T getValue() { 63 | if (!loaded) { 64 | this.value = load(); 65 | loaded = true; 66 | } 67 | return this.value; 68 | } 69 | 70 | public String getName() { 71 | return name; 72 | } 73 | 74 | private void write(T value) { 75 | SharedPreferences.Editor editor = sp.edit(); 76 | 77 | if (value instanceof String) { 78 | 79 | editor.putString(name, (String) value); 80 | 81 | } else if (value instanceof Integer) { 82 | 83 | editor.putInt(name, (Integer) value); 84 | 85 | } else if (value instanceof Float) { 86 | 87 | editor.putFloat(name, (Float) value); 88 | 89 | } else if (value instanceof Long) { 90 | 91 | editor.putLong(name, (Long) value); 92 | 93 | } else if (value instanceof Boolean) { 94 | 95 | editor.putBoolean(name, (Boolean) value); 96 | 97 | } 98 | 99 | editor.commit(); 100 | } 101 | 102 | @SuppressWarnings("unchecked") 103 | private T load() { 104 | 105 | if (type == String.class) { 106 | 107 | return (T) sp.getString(name, (String) defValue); 108 | 109 | } else if (type == Integer.class) { 110 | 111 | return (T) Integer.valueOf(sp.getInt(name, (Integer) defValue)); 112 | 113 | } else if (type == Float.class) { 114 | 115 | return (T) Float.valueOf(sp.getFloat(name, (Float) defValue)); 116 | 117 | } else if (type == Long.class) { 118 | 119 | return (T) Long.valueOf(sp.getLong(name, (Long) defValue)); 120 | 121 | } else if (type == Boolean.class) { 122 | 123 | return (T) Boolean.valueOf(sp.getBoolean(name, (Boolean) defValue)); 124 | 125 | } 126 | 127 | return null; 128 | } 129 | 130 | public void delete() { 131 | sp.edit().remove(name).commit(); 132 | clear(); 133 | } 134 | 135 | public static void initialize(SharedPreferences sp) { 136 | CachedValue.sharedPref = sp; 137 | } 138 | 139 | public void setSharedPreferences(SharedPreferences sp) { 140 | this.sp = sp; 141 | } 142 | 143 | public void clear() { 144 | loaded = false; 145 | this.value = null; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/FlashMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | public enum FlashMode { 27 | ON(0, "On"), AUTO(1, "Auto"), OFF(2, "Off"); 28 | 29 | private int id; 30 | 31 | private String name; 32 | 33 | FlashMode(int id, String name) { 34 | this.id = id; 35 | this.name = name; 36 | } 37 | 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public static FlashMode getFlashModeById(int id) { 43 | for (FlashMode mode : values()) { 44 | if (mode.id == id) { 45 | return mode; 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return name; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/FocusMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | public enum FocusMode { 27 | 28 | AUTO(0, "Auto"), TOUCH(1, "Touch"); 29 | 30 | private int id; 31 | 32 | private String name; 33 | 34 | FocusMode(int id, String name) { 35 | this.id = id; 36 | this.name = name; 37 | } 38 | 39 | public int getId() { 40 | return id; 41 | } 42 | 43 | public static FocusMode getFocusModeById(int id) { 44 | for (FocusMode mode : values()) { 45 | if (mode.id == id) { 46 | return mode; 47 | } 48 | } 49 | return null; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return name; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/HDRMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | public enum HDRMode { 27 | 28 | NONE(0, "None"), ON(1, "On"), OFF(2, "Off"); 29 | 30 | private int id; 31 | private String name; 32 | 33 | HDRMode(int id, String name) { 34 | this.id = id; 35 | this.name = name; 36 | } 37 | 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public static HDRMode getHDRModeById(int id) { 43 | for (HDRMode mode : values()) { 44 | if (mode.id == id) { 45 | return mode; 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return name; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/PictureSize.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | public class PictureSize { 27 | 28 | public int width; 29 | 30 | public int height; 31 | 32 | public Ratio ratio; 33 | 34 | public PictureSize(int width, int height, Ratio ratio) { 35 | this.width = width; 36 | this.height = height; 37 | this.ratio = ratio; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/Quality.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | public enum Quality { 27 | HIGH(0, "High"), MEDIUM(1, "Medium"), LOW(2, "Low"); 28 | 29 | private int id; 30 | 31 | private String name; 32 | 33 | Quality(int id, String name) { 34 | this.id = id; 35 | this.name = name; 36 | } 37 | 38 | public int getId() { 39 | return id; 40 | } 41 | 42 | public static Quality getQualityById(int id) { 43 | for (Quality mode : values()) { 44 | if (mode.id == id) { 45 | return mode; 46 | } 47 | } 48 | return null; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return name; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/model/Ratio.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.model; 25 | 26 | public enum Ratio { 27 | R_4x3(0, 4, 3), R_16x9(1, 16, 9); 28 | 29 | private int id; 30 | 31 | public int w; 32 | 33 | public int h; 34 | 35 | Ratio(int id, int w, int h) { 36 | this.id = id; 37 | this.w = w; 38 | this.h = h; 39 | } 40 | 41 | public int getId() { 42 | return id; 43 | } 44 | 45 | public static Ratio getRatioById(int id) { 46 | for (Ratio ratio : values()) { 47 | if (ratio.id == id) { 48 | return ratio; 49 | } 50 | } 51 | return null; 52 | } 53 | 54 | public static Ratio pickRatio(int width, int height) { 55 | for (Ratio ratio : values()) { 56 | if (width / ratio.w == height / ratio.h) { 57 | return ratio; 58 | } 59 | } 60 | return null; 61 | } 62 | 63 | @Override 64 | public String toString() { 65 | return w + ":" + h; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/CropPhotoTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import java.io.File; 27 | import java.io.FileNotFoundException; 28 | import java.io.FileOutputStream; 29 | import java.io.IOException; 30 | 31 | import timber.log.Timber; 32 | import android.graphics.Bitmap; 33 | import android.graphics.BitmapFactory; 34 | import android.graphics.RectF; 35 | import android.os.AsyncTask; 36 | 37 | import com.yalantis.cameramodule.CameraConst; 38 | import com.yalantis.cameramodule.interfaces.PhotoSavedListener; 39 | 40 | public class CropPhotoTask extends AsyncTask { 41 | 42 | private String path; 43 | private int width; 44 | private int height; 45 | private RectF rect; 46 | private PhotoSavedListener callback; 47 | 48 | public CropPhotoTask(String path, int width, int height, RectF rect, PhotoSavedListener callback) { 49 | this.path = path; 50 | this.rect = rect; 51 | this.width = width; 52 | this.height = height; 53 | this.callback = callback; 54 | } 55 | 56 | @Override 57 | protected Void doInBackground(Void... params) { 58 | Bitmap src = BitmapFactory.decodeFile(path); 59 | float koefW = (float) width / (float) src.getWidth(); 60 | float koefH = (float) height / (float) src.getHeight(); 61 | 62 | rect.top /= koefH; 63 | rect.left /= koefW; 64 | rect.right /= koefW; 65 | rect.bottom /= koefH; 66 | width = (int) rect.width(); 67 | height = (int) rect.height(); 68 | 69 | Bitmap bitmap = Bitmap.createBitmap(src, (int) rect.left, (int) rect.top, width, height); 70 | 71 | FileOutputStream fos = null; 72 | try { 73 | fos = new FileOutputStream(new File(path)); 74 | 75 | bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos); 76 | 77 | } catch (FileNotFoundException e) { 78 | Timber.e(e, "File not found: " + e.getMessage()); 79 | } finally { 80 | try { 81 | if (fos != null) { 82 | fos.close(); 83 | } 84 | } catch (IOException e) { 85 | Timber.e(e, e.getMessage()); 86 | } 87 | } 88 | bitmap.recycle(); 89 | 90 | return null; 91 | } 92 | 93 | @Override 94 | protected void onPostExecute(Void aVoid) { 95 | super.onPostExecute(aVoid); 96 | if (callback != null) { 97 | callback.photoSaved(path, null); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/ManagedTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import android.graphics.Bitmap; 27 | import android.graphics.drawable.Drawable; 28 | 29 | import com.squareup.picasso.Picasso; 30 | import com.squareup.picasso.Target; 31 | import com.yalantis.cameramodule.interfaces.StorageCallback; 32 | 33 | public class ManagedTarget implements Target { 34 | 35 | private Target target; 36 | private String path; 37 | private StorageCallback callback; 38 | 39 | public ManagedTarget(Target target, String path, StorageCallback callback) { 40 | this.target = target; 41 | this.path = path; 42 | this.callback = callback; 43 | callback.addTarget(this); 44 | } 45 | 46 | @Override 47 | public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { 48 | target.onBitmapLoaded(bitmap, from); 49 | callback.setBitmap(path, bitmap); 50 | callback.removeTarget(this); 51 | } 52 | 53 | @Override 54 | public void onBitmapFailed(Drawable errorDrawable) { 55 | target.onBitmapFailed(errorDrawable); 56 | callback.removeTarget(this); 57 | } 58 | 59 | @Override 60 | public void onPrepareLoad(Drawable placeHolderDrawable) { 61 | target.onPrepareLoad(placeHolderDrawable); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | return path.hashCode(); 67 | } 68 | 69 | @Override 70 | public boolean equals(Object o) { 71 | if (super.equals(o)) { 72 | return true; 73 | } 74 | if (o == null) { 75 | return false; 76 | } 77 | if (o.getClass() != this.getClass()) { 78 | return false; 79 | } 80 | ManagedTarget other = (ManagedTarget) o; 81 | return other.path.equals(path); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/PhotoUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import java.io.File; 27 | 28 | public class PhotoUtil { 29 | 30 | public static void deletePhoto(String path) { 31 | File file = new File(path); 32 | file.delete(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/RotatePhotoTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import java.io.File; 27 | import java.io.FileNotFoundException; 28 | import java.io.FileOutputStream; 29 | import java.io.IOException; 30 | 31 | import timber.log.Timber; 32 | import android.graphics.Bitmap; 33 | import android.graphics.BitmapFactory; 34 | import android.graphics.Matrix; 35 | import android.os.AsyncTask; 36 | 37 | import com.yalantis.cameramodule.CameraConst; 38 | import com.yalantis.cameramodule.interfaces.PhotoSavedListener; 39 | 40 | public class RotatePhotoTask extends AsyncTask { 41 | 42 | private String path; 43 | private float angle; 44 | private PhotoSavedListener callback; 45 | 46 | public RotatePhotoTask(String path, float angle, PhotoSavedListener callback) { 47 | this.path = path; 48 | this.angle = angle; 49 | this.callback = callback; 50 | } 51 | 52 | @Override 53 | protected Void doInBackground(Void... params) { 54 | Bitmap bitmap = BitmapFactory.decodeFile(path); // todo NPE 55 | Matrix matrix = new Matrix(); 56 | matrix.postRotate(angle); 57 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 58 | FileOutputStream fos = null; 59 | try { 60 | fos = new FileOutputStream(new File(path)); 61 | 62 | bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos); 63 | 64 | } catch (FileNotFoundException e) { 65 | Timber.e(e, "File not found: " + e.getMessage()); 66 | } finally { 67 | try { 68 | if (fos != null) { 69 | fos.close(); 70 | } 71 | } catch (IOException e) { 72 | Timber.e(e, e.getMessage()); 73 | } 74 | } 75 | bitmap.recycle(); 76 | 77 | return null; 78 | } 79 | 80 | @Override 81 | protected void onPostExecute(Void aVoid) { 82 | super.onPostExecute(aVoid); 83 | if (callback != null) { 84 | callback.photoSaved(path, null); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/SavingBitmapTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import java.io.File; 27 | import java.io.FileNotFoundException; 28 | import java.io.FileOutputStream; 29 | import java.io.IOException; 30 | 31 | import timber.log.Timber; 32 | import android.graphics.Bitmap; 33 | import android.os.AsyncTask; 34 | 35 | import com.yalantis.cameramodule.CameraConst; 36 | import com.yalantis.cameramodule.interfaces.PhotoSavedListener; 37 | 38 | public class SavingBitmapTask extends AsyncTask { 39 | 40 | private Bitmap bitmap; 41 | private String path; 42 | private PhotoSavedListener callback; 43 | 44 | public SavingBitmapTask(Bitmap bitmap, String path, PhotoSavedListener callback) { 45 | this.bitmap = bitmap; 46 | this.path = path; 47 | this.callback = callback; 48 | } 49 | 50 | @Override 51 | protected Void doInBackground(Void... params) { 52 | FileOutputStream fos = null; 53 | try { 54 | fos = new FileOutputStream(new File(path)); 55 | 56 | if (bitmap != null && !bitmap.isRecycled()) { 57 | bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos); 58 | } 59 | 60 | } catch (FileNotFoundException e) { 61 | Timber.e(e, "File not found: " + e.getMessage()); 62 | } finally { 63 | try { 64 | if (fos != null) { 65 | fos.close(); 66 | } 67 | } catch (IOException e) { 68 | Timber.e(e, e.getMessage()); 69 | } 70 | } 71 | 72 | return null; 73 | } 74 | 75 | @Override 76 | protected void onPostExecute(Void aVoid) { 77 | super.onPostExecute(aVoid); 78 | if (callback != null) { 79 | callback.photoSaved(path, null); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/SavingPhotoTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import java.io.File; 27 | import java.io.FileNotFoundException; 28 | import java.io.FileOutputStream; 29 | import java.io.IOException; 30 | 31 | import timber.log.Timber; 32 | import android.graphics.Bitmap; 33 | import android.graphics.BitmapFactory; 34 | import android.graphics.Matrix; 35 | import android.media.ExifInterface; 36 | import android.os.AsyncTask; 37 | import android.os.Environment; 38 | 39 | import com.yalantis.cameramodule.CameraConst; 40 | import com.yalantis.cameramodule.interfaces.PhotoSavedListener; 41 | 42 | public class SavingPhotoTask extends AsyncTask { 43 | 44 | private byte[] data; 45 | private String name; 46 | private String path; 47 | private int orientation; 48 | private PhotoSavedListener callback; 49 | 50 | public SavingPhotoTask(byte[] data, String name, String path, int orientation) { 51 | this(data, name, path, orientation, null); 52 | } 53 | 54 | public SavingPhotoTask(byte[] data, String name, String path, int orientation, PhotoSavedListener callback) { 55 | this.data = data; 56 | this.name = name; 57 | this.path = path; 58 | this.orientation = orientation; 59 | this.callback = callback; 60 | } 61 | 62 | @Override 63 | protected File doInBackground(Void... params) { 64 | File photo = getOutputMediaFile(); 65 | if (photo == null) { 66 | Timber.e("Error creating media file, check storage permissions"); 67 | return null; 68 | } 69 | 70 | FileOutputStream fos = null; 71 | try { 72 | fos = new FileOutputStream(photo); 73 | if (orientation == ExifInterface.ORIENTATION_UNDEFINED) { 74 | saveByteArray(fos, data); 75 | } else { 76 | saveByteArrayWithOrientation(fos, data, orientation); 77 | } 78 | 79 | } catch (FileNotFoundException e) { 80 | Timber.e(e, "File not found: " + e.getMessage()); 81 | } catch (IOException e) { 82 | Timber.e(e, "File write failure: " + e.getMessage()); 83 | } finally { 84 | try { 85 | if (fos != null) { 86 | fos.close(); 87 | } 88 | } catch (IOException e) { 89 | Timber.e(e, e.getMessage()); 90 | } 91 | } 92 | 93 | return photo; 94 | } 95 | 96 | private void saveByteArray(FileOutputStream fos, byte[] data) throws IOException { 97 | long time = System.currentTimeMillis(); 98 | fos.write(data); 99 | Timber.d("saveByteArray: %1dms", System.currentTimeMillis() - time); 100 | } 101 | 102 | private void saveByteArrayWithOrientation(FileOutputStream fos, byte[] data, int orientation) { 103 | long totalTime = System.currentTimeMillis(); 104 | long time = System.currentTimeMillis(); 105 | 106 | Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); 107 | Timber.d("decodeByteArray: %1dms", System.currentTimeMillis() - time); 108 | 109 | time = System.currentTimeMillis(); 110 | if (orientation != 0 && bitmap.getWidth() > bitmap.getHeight()) { 111 | Matrix matrix = new Matrix(); 112 | matrix.postRotate(orientation); 113 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 114 | Timber.d("createBitmap: %1dms", System.currentTimeMillis() - time); 115 | } 116 | time = System.currentTimeMillis(); 117 | bitmap.compress(Bitmap.CompressFormat.JPEG, CameraConst.COMPRESS_QUALITY, fos); 118 | Timber.d("compress: %1dms", System.currentTimeMillis() - time); 119 | 120 | bitmap.recycle(); 121 | 122 | Timber.d("saveByteArrayWithOrientation: %1dms", System.currentTimeMillis() - totalTime); 123 | } 124 | 125 | @Override 126 | protected void onPostExecute(File file) { 127 | super.onPostExecute(file); 128 | photoSaved(file); 129 | } 130 | 131 | private void photoSaved(File photo) { 132 | if (photo != null) { 133 | if (callback != null) { 134 | callback.photoSaved(photo.getPath(), photo.getName()); 135 | } 136 | } 137 | } 138 | 139 | /** 140 | * Create a File for saving an image 141 | */ 142 | private File getOutputMediaFile() { 143 | // To be safe, we should check that the SDCard is mounted 144 | if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { 145 | Timber.e("External storage " + Environment.getExternalStorageState()); 146 | return null; 147 | } 148 | 149 | File dir = new File(path); 150 | // Create the storage directory if it doesn't exist 151 | if (!dir.exists()) { 152 | if (!dir.mkdirs()) { 153 | Timber.e("Failed to create directory"); 154 | return null; 155 | } 156 | } 157 | 158 | return new File(dir.getPath() + File.separator + name); 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /CameraModule/src/main/java/com/yalantis/cameramodule/util/ScaleTransformation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2014 Zillow 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.yalantis.cameramodule.util; 25 | 26 | import android.graphics.Bitmap; 27 | import android.graphics.Matrix; 28 | 29 | import com.squareup.picasso.Transformation; 30 | 31 | public class ScaleTransformation implements Transformation { 32 | 33 | private float width; 34 | private float height; 35 | 36 | public ScaleTransformation(float width, float height) { 37 | this.width = width; 38 | this.height = height; 39 | } 40 | 41 | @Override 42 | public Bitmap transform(Bitmap source) { 43 | float sWidth = source.getWidth(); 44 | float sHeight = source.getHeight(); 45 | 46 | float xScale; 47 | float yScale; 48 | if (sWidth < sHeight) { 49 | yScale = height / sHeight; 50 | xScale = yScale; 51 | } else { 52 | xScale = width / sWidth; 53 | yScale = xScale; 54 | } 55 | 56 | Matrix matrix = new Matrix(); 57 | matrix.postScale(xScale, yScale); 58 | Bitmap scaledBitmap = Bitmap.createBitmap(source, 0, 0, (int) sWidth, (int) sHeight, matrix, true); 59 | 60 | scaledBitmap.getWidth(); 61 | scaledBitmap.getHeight(); 62 | if (scaledBitmap != source) { 63 | source.recycle(); 64 | } 65 | 66 | return scaledBitmap; 67 | } 68 | 69 | @Override 70 | public String key() { 71 | return "scaleTo" + width + "x" + height; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-hdpi/ic_camera_capture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-hdpi/ic_camera_capture.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-hdpi/ic_camera_capture_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-hdpi/ic_camera_capture_pressed.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-mdpi/ic_camera_capture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-mdpi/ic_camera_capture.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-mdpi/ic_camera_capture_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-mdpi/ic_camera_capture_pressed.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xhdpi/ic_camera_capture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xhdpi/ic_camera_capture.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xhdpi/ic_camera_capture_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xhdpi/ic_camera_capture_pressed.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xxhdpi/cam_flash_auto_icn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xxhdpi/cam_flash_auto_icn.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xxhdpi/cam_flash_fill_flash_icn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xxhdpi/cam_flash_fill_flash_icn.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xxhdpi/cam_flash_off_icn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xxhdpi/cam_flash_off_icn.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xxhdpi/ic_camera_capture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xxhdpi/ic_camera_capture.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable-xxhdpi/ic_camera_capture_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable-xxhdpi/ic_camera_capture_pressed.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable/bg_transparent_clickable.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable/camera_capture.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable/input.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable/input.9.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable/no_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable/no_image.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/drawable/sheet_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Yalantis/CameraModule/fca60cd2662c1768c68d383608600dd3361cc20f/CameraModule/src/main/res/drawable/sheet_shadow.png -------------------------------------------------------------------------------- /CameraModule/src/main/res/layout/activity_photo.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 30 | 31 | 35 | 36 | 42 | 43 | -------------------------------------------------------------------------------- /CameraModule/src/main/res/layout/activity_with_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 28 | 29 | 33 | 34 | -------------------------------------------------------------------------------- /CameraModule/src/main/res/layout/dialog_camera_params.xml: -------------------------------------------------------------------------------- 1 | 2 | 24 | 25 | 28 | 29 | 31 | 32 | 35 | 36 | 39 | 40 | 41 | 42 | 44 | 45 | 48 | 49 | 52 | 53 | 54 | 55 | 56 | 57 | 60 | 61 | 64 | 65 | 66 | 67 | 70 | 71 | 74 | 75 | 78 | 79 | 80 | 81 |