CameraUtils.java
8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package com.bitstrips.imoji.hardware;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Matrix;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Base64;
import android.util.Log;
import com.bitstrips.imoji.injection.ForApplication;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.inject.Inject;
public class CameraUtils
{
public static final String CAMERA_PERMISSIONS = "android.permission.CAMERA";
public static final String TAG = "CameraUtils";
private static int a = 768;
private static int b = 90;
private static int c = 300000;
private static String d = "data:image/jpeg;base64,";
private final Context e;
@Inject
public CameraUtils(@ForApplication Context paramContext)
{
this.e = paramContext;
}
public static int calculateInSampleSize(BitmapFactory.Options paramOptions, int paramInt1, int paramInt2)
{
int k = paramOptions.outHeight;
int m = paramOptions.outWidth;
int j = 1;
int i = 1;
if ((k > paramInt2) || (m > paramInt1))
{
k /= 2;
m /= 2;
for (;;)
{
if (k / i < paramInt2)
{
j = i;
if (m / i < paramInt1) {
break;
}
}
i *= 2;
}
}
return j;
}
public static BitmapFactory.Options decodeBounds(InputStream paramInputStream)
throws IOException
{
BitmapFactory.Options localOptions = new BitmapFactory.Options();
localOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(paramInputStream, null, localOptions);
paramInputStream.reset();
return localOptions;
}
public static String getBase64String(Bitmap paramBitmap)
{
if (paramBitmap == null) {}
for (;;)
{
return null;
try
{
ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
paramBitmap.compress(Bitmap.CompressFormat.JPEG, b, localByteArrayOutputStream);
paramBitmap = Base64.encodeToString(localByteArrayOutputStream.toByteArray(), 0);
paramBitmap = d + paramBitmap;
int i = paramBitmap.length();
int j = c;
if (i <= j) {
return paramBitmap;
}
}
catch (Exception paramBitmap) {}
}
return null;
}
public static Bitmap getDownScaledBitmap(InputStream paramInputStream, int paramInt1, int paramInt2)
{
try
{
Object localObject = decodeBounds(paramInputStream);
BitmapFactory.Options localOptions = new BitmapFactory.Options();
localOptions.inSampleSize = calculateInSampleSize((BitmapFactory.Options)localObject, paramInt1, paramInt2);
localObject = BitmapFactory.decodeStream(paramInputStream, null, localOptions);
paramInputStream.reset();
return (Bitmap)localObject;
}
catch (Exception paramInputStream) {}
return null;
}
public static Bitmap getScaledBitmap(InputStream paramInputStream, int paramInt1, int paramInt2)
{
try
{
Object localObject = decodeBounds(paramInputStream);
float f = Math.max(((BitmapFactory.Options)localObject).outWidth / paramInt1, ((BitmapFactory.Options)localObject).outHeight / paramInt2);
if (f > 1.0F)
{
localObject = new BitmapFactory.Options();
((BitmapFactory.Options)localObject).inSampleSize = ((int)Math.pow(2.0D, (int)Math.ceil(Math.log(f) / Math.log(2.0D))));
}
for (localObject = BitmapFactory.decodeStream(paramInputStream, null, (BitmapFactory.Options)localObject);; localObject = BitmapFactory.decodeStream(paramInputStream))
{
paramInputStream.reset();
return (Bitmap)localObject;
}
return null;
}
catch (Exception paramInputStream) {}
}
public final Bitmap getFixedImage(CameraDetails paramCameraDetails, byte[] paramArrayOfByte, int paramInt, boolean paramBoolean)
{
try
{
ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(paramArrayOfByte);
if (paramBoolean) {}
for (paramArrayOfByte = getDownScaledBitmap(localByteArrayInputStream, paramInt, paramInt);; paramArrayOfByte = getScaledBitmap(localByteArrayInputStream, paramInt, paramInt))
{
localByteArrayInputStream.close();
if (paramArrayOfByte != null) {
break;
}
Log.e("CameraUtils", "Could not decode jpg data.");
return null;
}
paramInt = paramCameraDetails.cameraInfo.orientation;
paramCameraDetails = new Matrix();
paramCameraDetails.preScale(-1.0F, 1.0F);
paramCameraDetails.postRotate(360 - paramInt);
paramCameraDetails = Bitmap.createBitmap(paramArrayOfByte, 0, 0, paramArrayOfByte.getWidth(), paramArrayOfByte.getHeight(), paramCameraDetails, true);
paramArrayOfByte.recycle();
return paramCameraDetails;
}
catch (IOException paramCameraDetails)
{
Log.e("CameraUtils", "Failed to save rotated image.", paramCameraDetails);
}
return null;
}
public boolean hasPermissions()
{
return ContextCompat.checkSelfPermission(this.e, "android.permission.CAMERA") == 0;
}
public CameraDetails openFrontFacingCamera()
{
try
{
int j = Camera.getNumberOfCameras();
int i = 0;
while (i < j)
{
Camera.CameraInfo localCameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(i, localCameraInfo);
int k = localCameraInfo.facing;
if (k == 1) {
try
{
Camera localCamera = Camera.open(i);
if (localCamera != null)
{
CameraDetails localCameraDetails = new CameraDetails(localCamera, localCameraInfo);
localCamera.getParameters().set("orientation", "portrait");
localCamera.setDisplayOrientation(360 - localCameraInfo.orientation);
return localCameraDetails;
}
}
catch (RuntimeException localRuntimeException)
{
Log.e("CameraUtils", "Camera failed to open: " + localRuntimeException.getLocalizedMessage());
}
}
i += 1;
}
return null;
}
catch (Exception localException)
{
Log.w("CameraUtils", "Error opening camera", localException);
}
}
public void releaseCamera(@NonNull CameraDetails paramCameraDetails)
{
paramCameraDetails.camera.release();
}
public final boolean requestPermissions(Activity paramActivity, int paramInt)
{
if (!hasPermissions())
{
ActivityCompat.requestPermissions(paramActivity, new String[] { "android.permission.CAMERA" }, paramInt);
return true;
}
return false;
}
public void takeFixedPicture(@NonNull final CameraDetails paramCameraDetails, final int paramInt, final boolean paramBoolean, @NonNull final BitmapCallback paramBitmapCallback)
{
paramBitmapCallback = new Camera.PictureCallback()
{
public final void onPictureTaken(byte[] paramAnonymousArrayOfByte, Camera paramAnonymousCamera)
{
paramAnonymousArrayOfByte = CameraUtils.this.getFixedImage(paramCameraDetails, paramAnonymousArrayOfByte, paramInt, paramBoolean);
paramBitmapCallback.onPictureTaken(paramAnonymousArrayOfByte, paramCameraDetails);
}
};
paramCameraDetails.camera.takePicture(null, null, paramBitmapCallback);
}
public static abstract interface BitmapCallback
{
public abstract void onPictureTaken(Bitmap paramBitmap, CameraUtils.CameraDetails paramCameraDetails);
}
public static class CameraDetails
{
public Camera camera;
public Camera.CameraInfo cameraInfo;
public CameraDetails(Camera paramCamera, Camera.CameraInfo paramCameraInfo)
{
this.camera = paramCamera;
this.cameraInfo = paramCameraInfo;
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/bitstrips/imoji/hardware/CameraUtils.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/