getBitmapList() {
194 | return cameraControllerViewModel.bitmapList;
195 | }
196 |
197 | /**
198 | * This function is used to update the Preview Image
199 | *
200 | * @param path path of the image
201 | */
202 | void setBitmapToPreview(CaptureData path) {
203 | File originalImage;
204 | boolean isImage = path.getOriginalFileName().endsWith(".jpg");
205 | if (isImage) {
206 | originalImage = FileUtils.getFile(getContext(), bucketName, path.getOriginalFileName(), false);
207 | } else {
208 | originalImage = FileUtils.getFile(getContext(), bucketName, path.getOriginalFileName() + ".jpg");
209 | }
210 | // First decode with inJustDecodeBounds=true to check dimensions
211 | final BitmapFactory.Options options = new BitmapFactory.Options();
212 | // options.inJustDecodeBounds = true;
213 | BitmapFactory.decodeFile(originalImage.getPath(), options);
214 | // Calculate inSampleSize
215 | options.inSampleSize = calculateInSampleSize(options, options.outWidth / 4, options.outHeight / 4);
216 | // Decode bitmap with inSampleSize set
217 | // options.inJustDecodeBounds = false;
218 | Bitmap bitmap = BitmapFactory.decodeFile(originalImage.getPath(), options);
219 | imageView.setImageBitmap(bitmap);
220 | }
221 |
222 | @Override
223 | public void onAttach(Context context) {
224 | super.onAttach(context);
225 | if (context instanceof PreviewFragment.OnPreviewFragmentInteraction) {
226 | mListener = (PreviewFragment.OnPreviewFragmentInteraction) context;
227 | } else {
228 | throw new RuntimeException(context.toString()
229 | + " must implement OnListFragmentInteractionListener");
230 | }
231 | }
232 |
233 | @Override
234 | public void onDetach() {
235 | super.onDetach();
236 | mListener = null;
237 | }
238 |
239 | /**
240 | * This Listener is used to communicate with Parent Activity {@link CameraControllerActivity}
241 | */
242 | public interface OnPreviewFragmentInteraction {
243 | /**
244 | * When user clicks on camera icon or close icon
245 | */
246 | void goToCaptureView();
247 |
248 | /**
249 | * When user clicks Done button
250 | */
251 | void onComplete();
252 | }
253 | }
254 |
--------------------------------------------------------------------------------
/easycam/src/main/java/in/balakrishnan/easycam/CameraControllerActivity.java:
--------------------------------------------------------------------------------
1 | package in.balakrishnan.easycam;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.content.res.Configuration;
7 | import android.graphics.Bitmap;
8 | import android.graphics.BitmapFactory;
9 | import android.hardware.SensorManager;
10 | import android.os.Bundle;
11 | import android.text.TextUtils;
12 | import android.util.Log;
13 | import android.view.OrientationEventListener;
14 |
15 | import androidx.annotation.NonNull;
16 | import androidx.annotation.Nullable;
17 | import androidx.appcompat.app.AppCompatActivity;
18 | import androidx.core.app.ActivityCompat;
19 | import androidx.core.content.ContextCompat;
20 | import androidx.fragment.app.Fragment;
21 | import androidx.lifecycle.ViewModelProvider;
22 |
23 | import java.io.File;
24 | import java.util.Arrays;
25 |
26 | import in.balakrishnan.easycam.capture.CaptureFragment;
27 | import in.balakrishnan.easycam.capture.CaptureFragmentBuilder;
28 | import in.balakrishnan.easycam.preview.PreviewFragment;
29 |
30 |
31 | public class CameraControllerActivity extends AppCompatActivity implements PreviewFragment.OnPreviewFragmentInteraction, CaptureFragment.OnCaptureInteractionListener {
32 | public static final int REQUEST_CAMERA_REQUEST_CODE = 113;
33 | private static final String TAG = "CameraControllerActivit";
34 | private static final int PERMISSION_REQUEST_CODE = 897;
35 | PreviewFragment previewFragment;
36 | CaptureFragment captureFragment;
37 | int orientation = 0;
38 | int temp = 0;
39 | CameraBundle io;
40 | Bundle bundle = new Bundle();
41 | boolean havePermission = false;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_camera_controller);
47 | bundle = savedInstanceState;
48 | Log.d(TAG, "onCreate: ");
49 | io = getIntent().getParcelableExtra("inputData");
50 | checkPermissionAndLaunch("from activity onCreate");
51 | }
52 |
53 | public void checkPermissionAndLaunch(String s) {
54 | Log.d(TAG, "checkPermissionAndLaunch: " + s);
55 | if (checkPermission())
56 | setup(bundle);
57 | else {
58 | ActivityCompat.requestPermissions(this,
59 | new String[]{Manifest.permission.CAMERA},
60 | PERMISSION_REQUEST_CODE);
61 | }
62 | }
63 |
64 | @Override
65 | public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
66 | if (requestCode == PERMISSION_REQUEST_CODE) {
67 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
68 | setup(bundle);
69 | } else {
70 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
71 | != PackageManager.PERMISSION_GRANTED) {
72 | // TODO: 2019-12-26 Request Camera permission
73 | }
74 | }
75 | }
76 | }
77 |
78 | @Override
79 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
80 | super.onActivityResult(requestCode, resultCode, data);
81 | Log.d(TAG, "onActivityResult: " + requestCode);
82 | if (requestCode == REQUEST_CAMERA_REQUEST_CODE) {
83 | checkPermissionAndLaunch("from activity onActivityResult");
84 | }
85 |
86 | }
87 |
88 | private void setup(Bundle savedInstanceState) {
89 | havePermission = true;
90 | setupOrientationListener();
91 | if (io.isClearBucket())
92 | FileUtils.clearAllFiles(this, io.getBucket());
93 | if (io.isPreLoaded())
94 | loadFilesFromBucket();
95 | if (null == savedInstanceState) {
96 | goToCaptureView();
97 | }
98 | }
99 |
100 | private boolean checkPermission() {
101 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
102 | != PackageManager.PERMISSION_GRANTED) {
103 | // Permission is not granted
104 |
105 | return false;
106 | }
107 | return true;
108 | }
109 |
110 | private void loadFilesFromBucket() {
111 | File[] files = FileUtils.getAllFiles(this, io.getBucket());
112 | Arrays.sort(files);
113 | for (File file : files) {
114 | Log.d(TAG, "loadFilesFromBucket: " + file.getName());
115 | Bitmap bitmap = BitmapFactory.decodeFile(file.getPath(), new BitmapFactory.Options());
116 | CaptureData captureData = new CaptureData(bitmap, file.getName());
117 | obtainViewModel().addToList(captureData);
118 | }
119 | }
120 |
121 | private void setupOrientationListener() {
122 | //Orientation Listener to detect the rotation
123 | OrientationEventListener mOrientationListener = new OrientationEventListener(this,
124 | SensorManager.SENSOR_DELAY_NORMAL) {
125 |
126 | @Override
127 | public void onOrientationChanged(int rotation) {
128 | if (rotation > 330 && rotation < 360 || rotation < 30) {
129 | orientation = 0;
130 | } else if (rotation > 60 && rotation < 120) {
131 | orientation = 3;
132 | } else if (rotation > 150 && rotation < 210) {
133 | orientation = 2;
134 | } else if (rotation > 240 && rotation < 300) {
135 | orientation = 1;
136 | }
137 | if (temp != orientation) {
138 | int rotationResult = temp - orientation;
139 | if (rotationResult == -1 || rotationResult == 3) {
140 | captureFragment.rotateView(90);
141 | } else if (rotationResult == 1 || rotationResult == -3) {
142 | captureFragment.rotateView(-90);
143 | }
144 | temp = orientation;
145 | }
146 | }
147 | };
148 | mOrientationListener.enable();
149 |
150 | }
151 |
152 | /**
153 | * When fragments or the activity requires ViewModel, This function has to be called.
154 | *
155 | * NOTE : ViewModel is shared between fragments, If ViewModel is updated from one fragment,
156 | * updates occur in other fragment / Activity too.
157 | *
158 | * @return {CameraControllerViewModel.class}
159 | */
160 | public CameraControllerViewModel obtainViewModel() {
161 | return new ViewModelProvider(this).get(CameraControllerViewModel.class);
162 | }
163 |
164 | @Override
165 | public void goToCaptureView() {
166 | try {
167 | captureFragment = new CaptureFragmentBuilder().setBundle(io).createCaptureFragment();
168 | getSupportFragmentManager().beginTransaction()
169 | .replace(R.id.fl_container, captureFragment)
170 | .commit();
171 | } catch (Exception e) {
172 | e.printStackTrace();
173 | }
174 | }
175 |
176 | @Override
177 | public void onComplete() {
178 |
179 | int t = 0;
180 | Log.d(TAG, "onComplete: onComplete called");
181 | File directory = new File(FileUtils.getFilePath(this, io.getBucket()));
182 | File[] imageList = directory.listFiles();
183 | String[] paths = new String[imageList.length];
184 | if (imageList != null) {
185 | for (File file : imageList) {
186 | paths[t++] = file.getPath();
187 | }
188 | }
189 | Arrays.sort(paths);
190 | Intent intent = new Intent();
191 | intent.putExtra("resultData", paths);
192 | setResult(AppCompatActivity.RESULT_OK, intent);
193 | if (TextUtils.isEmpty(io.getClassName())) {
194 | finish();
195 | } else {
196 | ClassLauncher classLauncher = new ClassLauncher(this);
197 | try {
198 | Bundle bundle = new Bundle();
199 | bundle.putStringArray("resultData", paths);
200 | classLauncher.launchActivity(io.className, bundle);
201 | finish();
202 | } catch (Exception e) {
203 | e.printStackTrace();
204 | }
205 | }
206 |
207 |
208 | }
209 |
210 | @Override
211 | public void goToPreviewMode() {
212 | previewFragment = PreviewFragment.newInstance(io.getMin_photo(), io.getMax_photo(), io.getBucket());
213 | getSupportFragmentManager().beginTransaction()
214 | .replace(R.id.fl_container, previewFragment)
215 | .commit();
216 | }
217 |
218 | @Override
219 | public void onBackPressed() {
220 | if (!havePermission) super.onBackPressed();
221 | if (isBackStack()) {
222 | Log.d(TAG, "onBackPressed: " + io.isSetResultOnBackPressed());
223 | if (io.isSetResultOnBackPressed())
224 | onComplete();
225 | super.onBackPressed();
226 | }
227 | }
228 |
229 | /**
230 | * This function is used to check if Preview fragment or upload fragment is top of the stack.
231 | * If it is present then it returns true, otherwise false
232 | *
233 | * @return boolean
234 | */
235 |
236 | private boolean isBackStack() {
237 | for (Fragment fragment : getSupportFragmentManager().getFragments()) {
238 | if (fragment != null)
239 | if (fragment instanceof PreviewFragment) {
240 | getSupportFragmentManager().beginTransaction().remove(fragment).commit();
241 | goToCaptureView();
242 | return false;
243 | }
244 | }
245 | return true;
246 | }
247 |
248 | @Override
249 | public void onConfigurationChanged(@NonNull Configuration newConfig) {
250 | super.onConfigurationChanged(newConfig);
251 | Log.d(TAG, "onConfigurationChanged: ");
252 | }
253 |
254 | /**
255 | * Returns current orientation of the `device`
256 | *
257 | * @return
258 | */
259 | public int getOrientation() {
260 | return orientation;
261 | }
262 |
263 | }
264 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/easycam/src/main/java/in/balakrishnan/easycam/CameraBundle.java:
--------------------------------------------------------------------------------
1 | package in.balakrishnan.easycam;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import android.util.Log;
6 |
7 | /**
8 | * Created by BalaKrishnan on 2019-07-15.
9 | *
10 | * This Object is used to create {@link CameraControllerActivity}
11 | * This model is used to configure both {@link in.balakrishnan.easycam.capture.CaptureFragment}
12 | * and {@link in.balakrishnan.easycam.preview.PreviewFragment}
13 | */
14 | public class CameraBundle implements Parcelable {
15 | public static final Creator CREATOR = new Creator() {
16 | @Override
17 | public CameraBundle createFromParcel(Parcel in) {
18 | return new CameraBundle(in);
19 | }
20 |
21 | @Override
22 | public CameraBundle[] newArray(int size) {
23 | return new CameraBundle[size];
24 | }
25 | };
26 | private static final String TAG = "CameraBundle";
27 | String className;
28 | /**
29 | * Preview visibility control set true to make it visible
30 | */
31 | private boolean previewIconVisibility;
32 | /**
33 | * Set flag as true to enable preview page redirection
34 | */
35 | private boolean previewPageRedirection;
36 | /**
37 | * Set this flag as true to enable no of photos taken above Preview icon, This is linked with {@see previewIconVisibility}
38 | */
39 | private boolean previewEnableCount;
40 | /**
41 | * Set this flag true to enable / visible done button,
42 | * which is usually used for finishing the capture of image
43 | */
44 | private boolean enableDone;
45 | /**
46 | * This String used to alter the value of Done / Finish button
47 | */
48 | private String doneButtonString;
49 | /**
50 | * This 'int' value is used to set value background for Capture button
51 | */
52 | private int captureButtonDrawable;
53 | /**
54 | * This 'int' value is used to set value background for Done button
55 | */
56 | private int doneButtonDrawable;
57 | /**
58 | * This value specifies minimum number of photos required
59 | */
60 | private int min_photo;
61 | /**
62 | * This value specifies maximum number of photos allowed
63 | */
64 | private int max_photo;
65 | /**
66 | * Set this flag as true, if you need to take single image
67 | * If you set this as true, After taking single picture camera module will be closed automatically.
68 | */
69 | private boolean singlePhotoMode;
70 | /**
71 | * Set this flag as true to make preview as full screen preview
72 | */
73 | private boolean fullscreenMode;
74 | /**
75 | * Set this flag as true to enable manual focusing in capture module
76 | */
77 | private boolean manualFocus;
78 | /**
79 | * Set this flag as true to enable 'Preview' and 'Done' views animation using orientation
80 | */
81 | private boolean enableRotationAnimation;
82 | private String bucket;
83 | private boolean clearBucket;
84 | private boolean preLoaded;
85 | private boolean setResultOnBackPressed;
86 |
87 | public CameraBundle(
88 | boolean previewIconVisibility,
89 | boolean previewPageRedirection,
90 | boolean previewEnableCount,
91 | boolean enableDone,
92 | String doneButtonString,
93 | int captureButtonDrawable,
94 | int doneButtonDrawable,
95 | int min_photo,
96 | int max_photo,
97 | boolean singlePhotoMode,
98 | boolean fullscreenMode,
99 | boolean manualFocus,
100 | boolean enableRotationAnimation,
101 | String bucket,
102 | String className,
103 | boolean clearBucket,
104 | boolean preLoaded,
105 | boolean setResultOnBackPressed) {
106 | this.previewIconVisibility = previewIconVisibility;
107 | this.previewPageRedirection = previewPageRedirection;
108 | this.previewEnableCount = previewEnableCount;
109 | this.enableDone = enableDone;
110 | this.doneButtonString = doneButtonString;
111 | this.captureButtonDrawable = captureButtonDrawable;
112 | this.doneButtonDrawable = doneButtonDrawable;
113 | this.min_photo = min_photo;
114 | this.max_photo = max_photo;
115 | this.singlePhotoMode = singlePhotoMode;
116 | this.fullscreenMode = fullscreenMode;
117 | this.manualFocus = manualFocus;
118 | this.enableRotationAnimation = enableRotationAnimation;
119 | this.bucket = bucket;
120 | this.className = className;
121 | this.clearBucket = clearBucket;
122 | this.preLoaded = preLoaded;
123 | this.setResultOnBackPressed = setResultOnBackPressed;
124 | Log.d(TAG, "CameraBundle: " + setResultOnBackPressed);
125 | }
126 |
127 |
128 | protected CameraBundle(Parcel in) {
129 | previewIconVisibility = in.readByte() != 0;
130 | previewPageRedirection = in.readByte() != 0;
131 | previewEnableCount = in.readByte() != 0;
132 | enableDone = in.readByte() != 0;
133 | doneButtonString = in.readString();
134 | captureButtonDrawable = in.readInt();
135 | doneButtonDrawable = in.readInt();
136 | min_photo = in.readInt();
137 | max_photo = in.readInt();
138 | singlePhotoMode = in.readByte() != 0;
139 | fullscreenMode = in.readByte() != 0;
140 | manualFocus = in.readByte() != 0;
141 | enableRotationAnimation = in.readByte() != 0;
142 | bucket = in.readString();
143 | className = in.readString();
144 | clearBucket = in.readByte() != 0;
145 | preLoaded = in.readByte() != 0;
146 | setResultOnBackPressed = in.readByte() != 0;
147 | }
148 |
149 | public String getClassName() {
150 | return className;
151 | }
152 |
153 | public void setClassName(String className) {
154 | this.className = className;
155 | }
156 |
157 | @Override
158 | public int describeContents() {
159 | return 0;
160 | }
161 |
162 | @Override
163 | public void writeToParcel(Parcel dest, int flags) {
164 | dest.writeByte((byte) (previewIconVisibility ? 1 : 0));
165 | dest.writeByte((byte) (previewPageRedirection ? 1 : 0));
166 | dest.writeByte((byte) (previewEnableCount ? 1 : 0));
167 | dest.writeByte((byte) (enableDone ? 1 : 0));
168 | dest.writeString(doneButtonString);
169 | dest.writeInt(captureButtonDrawable);
170 | dest.writeInt(doneButtonDrawable);
171 | dest.writeInt(min_photo);
172 | dest.writeInt(max_photo);
173 | dest.writeByte((byte) (singlePhotoMode ? 1 : 0));
174 | dest.writeByte((byte) (fullscreenMode ? 1 : 0));
175 | dest.writeByte((byte) (manualFocus ? 1 : 0));
176 | dest.writeByte((byte) (enableRotationAnimation ? 1 : 0));
177 | dest.writeString(bucket);
178 | dest.writeString(className);
179 | dest.writeByte((byte) (clearBucket ? 1 : 0));
180 | dest.writeByte((byte) (preLoaded ? 1 : 0));
181 | dest.writeByte((byte) (setResultOnBackPressed ? 1 : 0));
182 |
183 | }
184 |
185 | public boolean isPreLoaded() {
186 | return preLoaded;
187 | }
188 |
189 | public void setPreLoaded(boolean preLoaded) {
190 | this.preLoaded = preLoaded;
191 | }
192 |
193 | public boolean isClearBucket() {
194 | return clearBucket;
195 | }
196 |
197 | public void setClearBucket(boolean clearBucket) {
198 | this.clearBucket = clearBucket;
199 | }
200 |
201 | public boolean isPreviewIconVisibility() {
202 | return previewIconVisibility;
203 | }
204 |
205 | public void setPreviewIconVisibility(boolean previewIconVisibility) {
206 | this.previewIconVisibility = previewIconVisibility;
207 | }
208 |
209 | public boolean isSetResultOnBackPressed() {
210 | return setResultOnBackPressed;
211 | }
212 |
213 | public boolean isPreviewPageRedirection() {
214 | return previewPageRedirection;
215 | }
216 |
217 | public void setPreviewPageRedirection(boolean previewPageRedirection) {
218 | this.previewPageRedirection = previewPageRedirection;
219 | }
220 |
221 | public boolean isPreviewEnableCount() {
222 | return previewEnableCount;
223 | }
224 |
225 | public void setPreviewEnableCount(boolean previewEnableCount) {
226 | this.previewEnableCount = previewEnableCount;
227 | }
228 |
229 | public boolean isEnableDone() {
230 | return enableDone;
231 | }
232 |
233 | public void setEnableDone(boolean enableDone) {
234 | this.enableDone = enableDone;
235 | }
236 |
237 | public String getDoneButtonString() {
238 | return doneButtonString;
239 | }
240 |
241 | public void setDoneButtonString(String doneButtonString) {
242 | this.doneButtonString = doneButtonString;
243 | }
244 |
245 | public String getBucket() {
246 | return bucket;
247 | }
248 |
249 | public void setBucket(String bucket) {
250 | this.bucket = bucket;
251 | }
252 |
253 | public int getCaptureButtonDrawable() {
254 | return captureButtonDrawable;
255 | }
256 |
257 | public void setCaptureButtonDrawable(int captureButtonDrawable) {
258 | this.captureButtonDrawable = captureButtonDrawable;
259 | }
260 |
261 | public int getDoneButtonDrawable() {
262 | return doneButtonDrawable;
263 | }
264 |
265 | public void setDoneButtonDrawable(int doneButtonDrawable) {
266 | this.doneButtonDrawable = doneButtonDrawable;
267 | }
268 |
269 | public int getMin_photo() {
270 | return min_photo;
271 | }
272 |
273 | public void setMin_photo(int min_photo) {
274 | this.min_photo = min_photo;
275 | }
276 |
277 | public int getMax_photo() {
278 | return max_photo;
279 | }
280 |
281 | public void setMax_photo(int max_photo) {
282 | this.max_photo = max_photo;
283 | }
284 |
285 | public boolean isSinglePhotoMode() {
286 | return singlePhotoMode;
287 | }
288 |
289 | public void setSinglePhotoMode(boolean singlePhotoMode) {
290 | this.singlePhotoMode = singlePhotoMode;
291 | }
292 |
293 | public boolean isFullscreenMode() {
294 | return fullscreenMode;
295 | }
296 |
297 | public void setFullscreenMode(boolean fullscreenMode) {
298 | this.fullscreenMode = fullscreenMode;
299 | }
300 |
301 | public boolean isManualFocus() {
302 | return manualFocus;
303 | }
304 |
305 | public void setManualFocus(boolean manualFocus) {
306 | this.manualFocus = manualFocus;
307 | }
308 |
309 | public boolean isEnableRotationAnimation() {
310 | return enableRotationAnimation;
311 | }
312 |
313 | public void setEnableRotationAnimation(boolean enableRotationAnimation) {
314 | this.enableRotationAnimation = enableRotationAnimation;
315 | }
316 |
317 | @Override
318 | public String toString() {
319 | return "CameraBundle{" +
320 | "previewIconVisibility=" + previewIconVisibility +
321 | ", previewPageRedirection=" + previewPageRedirection +
322 | ", previewEnableCount=" + previewEnableCount +
323 | ", enableDone=" + enableDone +
324 | ", doneButtonString='" + doneButtonString + '\'' +
325 | ", captureButtonDrawable=" + captureButtonDrawable +
326 | ", doneButtonDrawable=" + doneButtonDrawable +
327 | ", min_photo=" + min_photo +
328 | ", max_photo=" + max_photo +
329 | ", singlePhotoMode=" + singlePhotoMode +
330 | ", fullscreenMode=" + fullscreenMode +
331 | ", manualFocus=" + manualFocus +
332 | ", enableRotationAnimation=" + enableRotationAnimation +
333 | '}';
334 | }
335 | }
336 |
--------------------------------------------------------------------------------
/easycam/src/main/java/in/balakrishnan/easycam/imageBadgeView/ImageBadgeView.java:
--------------------------------------------------------------------------------
1 | package in.balakrishnan.easycam.imageBadgeView;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Typeface;
6 | import android.graphics.drawable.Drawable;
7 | import android.util.AttributeSet;
8 |
9 | import in.balakrishnan.easycam.imageBadgeView.listener.OnBadgeCountChangeListener;
10 | import in.balakrishnan.easycam.imageBadgeView.util.DensityUtils;
11 |
12 | /**
13 | * Image View with a badge like notification count
14 | *
15 | * @author Ivan V on 18.02.2018.
16 | * @version 1.0
17 | */
18 | public class ImageBadgeView extends CircleImageView {
19 |
20 | private DrawerManager manager;
21 | private OnBadgeCountChangeListener onBadgeCountChangeListener;
22 |
23 | public ImageBadgeView(Context context) {
24 | super(context);
25 | initAttr(null);
26 | }
27 |
28 | public ImageBadgeView(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | initAttr(attrs);
31 | }
32 |
33 | public ImageBadgeView(Context context, AttributeSet attrs, int defStyleAttr) {
34 | super(context, attrs, defStyleAttr);
35 | initAttr(attrs);
36 | }
37 |
38 | private void initAttr(AttributeSet attrs) {
39 | manager = new DrawerManager(ImageBadgeView.this, attrs);
40 | }
41 |
42 | @Override
43 | protected void onDraw(Canvas canvas) {
44 | super.onDraw(canvas);
45 | manager.drawBadge(canvas);
46 | }
47 |
48 | /**
49 | * Register a callback to be invoked when counter of a badge changed.
50 | *
51 | * @param listener the callback that will run.
52 | */
53 | public void setOnBadgeCountChangeListener(OnBadgeCountChangeListener listener) {
54 | onBadgeCountChangeListener = listener;
55 | }
56 |
57 | /**
58 | * @return the badge counter value
59 | */
60 | public int getBadgeValue() {
61 | return manager.getBadge().getValue();
62 | }
63 |
64 | /**
65 | * Set a badge counter value and add change listener if it registered
66 | *
67 | * @param badgeValue new counter value
68 | */
69 | public ImageBadgeView setBadgeValue(int badgeValue) {
70 | manager.getBadge().setValue(badgeValue);
71 | if (onBadgeCountChangeListener != null) {
72 | onBadgeCountChangeListener.onCountChange(badgeValue);
73 | }
74 | invalidate();
75 | return this;
76 | }
77 |
78 | /**
79 | * Get the maximum value of a badge (by default setting 99)
80 | */
81 | public int getMaxBadgeValue() {
82 | return manager.getBadge().getMaxValue();
83 | }
84 |
85 | /**
86 | * Set the maximum value of a badge (by default setting 99)
87 | *
88 | * @param maxBadgeValue new maximum value for counter
89 | */
90 | public ImageBadgeView setMaxBadgeValue(int maxBadgeValue) {
91 | manager.getBadge().setMaxValue(maxBadgeValue);
92 | invalidate();
93 | return this;
94 | }
95 |
96 | /**
97 | * @return state of a badge visible
98 | */
99 | public boolean isVisibleBadge() {
100 | return manager.getBadge().isVisible();
101 | }
102 |
103 | /**
104 | * Set a badge visible state
105 | *
106 | * @param visible If state true a badge will be visible
107 | */
108 | public ImageBadgeView visibleBadge(boolean visible) {
109 | manager.getBadge().setVisible(visible);
110 | invalidate();
111 | return this;
112 | }
113 |
114 | /**
115 | * @return state of a badge vertical stretched
116 | */
117 | public boolean isRoundBadge() {
118 | return manager.getBadge().isRoundBadge();
119 | }
120 |
121 | /**
122 | * Define whether a badge can be stretched vertically
123 | *
124 | * @param roundBadge If param is true, a badge can be stretched vertically
125 | */
126 | public ImageBadgeView setRoundBadge(boolean roundBadge) {
127 | manager.getBadge().setRoundBadge(roundBadge);
128 | invalidate();
129 | return this;
130 | }
131 |
132 | /**
133 | * @return state of a badge fixed radius by width
134 | */
135 | public boolean isFixedRadius() {
136 | return manager.getBadge().isFixedRadius();
137 | }
138 |
139 | /**
140 | * Define whether a badge can be with fixed radius by width.
141 | * Badge can have only circle or square form.
142 | *
143 | * @param fixedRadius If param is true, a badge radius fixed
144 | */
145 | public ImageBadgeView setFixedRadius(boolean fixedRadius) {
146 | manager.getBadge().setFixedRadius(fixedRadius);
147 | invalidate();
148 | return this;
149 | }
150 |
151 | /**
152 | * State of a badge whether a badge can be oval form after first value number of counter
153 | *
154 | * @return state of a badge
155 | */
156 | public boolean isBadgeOvalAfterFirst() {
157 | return manager.getBadge().isOvalAfterFirst();
158 | }
159 |
160 | /**
161 | * Define whether a badge can be oval form after first value number of counter
162 | * Please use this method only for custom drawable badge background. See {@link #setBadgeBackground(Drawable)}.
163 | *
164 | * @param badgeOvalAfterFirst If param is true, a badge can be oval form after first value
165 | */
166 | public ImageBadgeView setBadgeOvalAfterFirst(boolean badgeOvalAfterFirst) {
167 | manager.getBadge().setOvalAfterFirst(badgeOvalAfterFirst);
168 | invalidate();
169 | return this;
170 | }
171 |
172 | /**
173 | * @return State whether the counter is showing
174 | */
175 | public boolean isShowCounter() {
176 | return manager.getBadge().isShowCounter();
177 | }
178 |
179 | /**
180 | * Specify whether the counter can be showing on a badge
181 | *
182 | * @param showCounter Specify whether the counter is shown
183 | */
184 | public ImageBadgeView setShowCounter(boolean showCounter) {
185 | manager.getBadge().setShowCounter(showCounter);
186 | invalidate();
187 | return this;
188 | }
189 |
190 | /**
191 | * State of a badge has limit counter
192 | *
193 | * @return state of a badge has limit
194 | */
195 | public boolean isLimitValue() {
196 | return manager.getBadge().isLimitValue();
197 | }
198 |
199 | /**
200 | * Define whether a badge counter can have limit
201 | *
202 | * @param badgeValueLimit If param is true, after max value (default 99) a badge will have counter 99+
203 | * Otherwise a badge will show the current value, e.g 101
204 | */
205 | public ImageBadgeView setLimitBadgeValue(boolean badgeValueLimit) {
206 | manager.getBadge().setLimitValue(badgeValueLimit);
207 | invalidate();
208 | return this;
209 | }
210 |
211 | /**
212 | * Get the current badge background color
213 | */
214 | public int getBadgeColor() {
215 | return manager.getBadge().getBadgeColor();
216 | }
217 |
218 | /**
219 | * Set the background color for a badge
220 | *
221 | * @param badgeColor the color of the background
222 | */
223 | public ImageBadgeView setBadgeColor(int badgeColor) {
224 | manager.getBadge().setBadgeColor(badgeColor);
225 | invalidate();
226 | return this;
227 | }
228 |
229 | /**
230 | * Get the current text color of a badge
231 | */
232 | public int getBadgeTextColor() {
233 | return manager.getBadge().getBadgeTextColor();
234 | }
235 |
236 | /**
237 | * Set the text color for a badge
238 | *
239 | * @param badgeTextColor the color of a badge text
240 | */
241 | public ImageBadgeView setBadgeTextColor(int badgeTextColor) {
242 | manager.getBadge().setBadgeTextColor(badgeTextColor);
243 | invalidate();
244 | return this;
245 | }
246 |
247 | /**
248 | * Get the current text size of a badge
249 | */
250 | public float getBadgeTextSize() {
251 | return manager.getBadge().getBadgeTextSize();
252 | }
253 |
254 | /**
255 | * Set the text size for a badge
256 | *
257 | * @param badgeTextSize the size of a badge text
258 | */
259 | public ImageBadgeView setBadgeTextSize(float badgeTextSize) {
260 | manager.getBadge().setBadgeTextSize(DensityUtils.dpToPx(badgeTextSize));
261 | invalidate();
262 | return this;
263 | }
264 |
265 | /**
266 | * Get padding of a badge
267 | */
268 | public float getBadgePadding() {
269 | return manager.getBadge().getPadding();
270 | }
271 |
272 | /**
273 | * Set a badge padding
274 | *
275 | * @param badgePadding the badge padding
276 | */
277 | public ImageBadgeView setBadgePadding(int badgePadding) {
278 | manager.getBadge().setPadding(DensityUtils.txtPxToSp(badgePadding));
279 | invalidate();
280 | return this;
281 | }
282 |
283 | /**
284 | * Get a badge radius
285 | */
286 | public float getBadgeRadius() {
287 | return manager.getBadge().getRadius();
288 | }
289 |
290 | /**
291 | * Set the badge fixed radius. Radius will not respond to changes padding or width of text.
292 | *
293 | * @param fixedBadgeRadius badge fixed radius value
294 | */
295 | public ImageBadgeView setFixedBadgeRadius(float fixedBadgeRadius) {
296 | manager.getBadge().setFixedRadiusSize(fixedBadgeRadius);
297 | invalidate();
298 | return this;
299 | }
300 |
301 | /**
302 | * Get the current typeface {@link Typeface} of a badge
303 | */
304 | public Typeface getBadgeTextFont() {
305 | return manager.getBadge().getBadgeTextFont();
306 | }
307 |
308 | /**
309 | * Set the typeface for a badge text
310 | *
311 | * @param font Font for a badge text
312 | */
313 | public ImageBadgeView setBadgeTextFont(Typeface font) {
314 | manager.getBadge().setBadgeTextFont(font);
315 | invalidate();
316 | return this;
317 | }
318 |
319 | /**
320 | * Get the style of the badge text. Matches the {@link Typeface} text style
321 | */
322 | public int getBadgeTextStyle() {
323 | return manager.getBadge().getTextStyle();
324 | }
325 |
326 | /**
327 | * Set the style of the badge text. Matches the {@link Typeface} text style
328 | *
329 | * @param badgeTextStyle Can be normal, bold, italic, bold_italic
330 | */
331 | public ImageBadgeView setBadgeTextStyle(int badgeTextStyle) {
332 | manager.getBadge().setTextStyle(badgeTextStyle);
333 | invalidate();
334 | return this;
335 | }
336 |
337 | /**
338 | * Get the background of a badge.
339 | */
340 | public int getBadgeBackground() {
341 | return manager.getBadge().getBadgeBackground();
342 | }
343 |
344 | /**
345 | * Set the custom background of a badge
346 | *
347 | * @param badgeBackground the {@link Drawable} background of a badge from resources
348 | */
349 | public ImageBadgeView setBadgeBackground(Drawable badgeBackground) {
350 | manager.getBadge().setBackgroundDrawable(badgeBackground);
351 | invalidate();
352 | return this;
353 | }
354 |
355 | /**
356 | * Get the background of a badge {@link Drawable} or null.
357 | */
358 | public Drawable getBadgeBackgroundDrawable() {
359 | return manager.getBadge().getBackgroundDrawable();
360 | }
361 |
362 | /**
363 | * Clear counter badge value
364 | */
365 | public void clearBadge() {
366 | manager.getBadge().clearValue();
367 | invalidate();
368 | }
369 |
370 | /**
371 | * Get position of a badge {@link BadgePosition}.
372 | *
373 | * @return {@link BadgePosition} position on ImageView by index
374 | */
375 | public int getBadgePosition() {
376 | return manager.getBadge().getPosition();
377 | }
378 |
379 | /**
380 | * Set badge position {@link BadgePosition} on ImageView
381 | *
382 | * @param position on this view {@link BadgePosition} top_left, top_right, bottom_left, bottom_right
383 | */
384 | public ImageBadgeView setBadgePosition(int position) {
385 | manager.getBadge().setPosition(position);
386 | invalidate();
387 | return this;
388 | }
389 | }
390 |
--------------------------------------------------------------------------------