48
48
import ie .yesequality .yesequality .utils .BitmapUtils ;
49
49
import ie .yesequality .yesequality .views .CameraOverlayView ;
50
50
51
- public class CameraMainActivityTest extends AppCompatActivity implements TextureView
51
+ public class CameraActivity extends AppCompatActivity implements TextureView
52
52
.SurfaceTextureListener ,
53
53
Camera .PictureCallback {
54
- public static final String TAG = "CameraMainActivity" ;
55
54
private static final int PICTURE_QUALITY = 100 ;
55
+ private static final int [] AllVoteBadges = new int []{R .drawable .ic_wm_i_voted ,
56
+ R .drawable .ic_wm_i_voted_color ,
57
+ R .drawable .ic_wm_its_yes ,
58
+ R .drawable .ic_wm_its_yes_color ,
59
+ R .drawable .ic_wm_thank_you ,
60
+ R .drawable .ic_wm_thank_you_color ,
61
+ R .drawable .ic_wm_vote_for_me ,
62
+ R .drawable .ic_wm_vote_for_me_color ,
63
+ R .drawable .ic_wm_yes_im_voting ,
64
+ R .drawable .ic_wm_yes_im_voting_color ,
65
+ R .drawable .ic_wm_we_voting ,
66
+ R .drawable .ic_wm_we_voting_color ,
67
+ R .drawable .ic_wm_ta ,
68
+ R .drawable .ic_wm_ta_color ,
69
+ R .drawable .ic_wm_yes ,
70
+ R .drawable .ic_wm_yes_color
71
+ };
72
+ private static int [] sVoteBadges = new int []{R .drawable .ic_wm_vote_for_me ,
73
+ R .drawable .ic_wm_vote_for_me_color ,
74
+ R .drawable .ic_wm_yes_im_voting ,
75
+ R .drawable .ic_wm_yes_im_voting_color ,
76
+ R .drawable .ic_wm_we_voting ,
77
+ R .drawable .ic_wm_we_voting_color ,
78
+ R .drawable .ic_wm_ta ,
79
+ R .drawable .ic_wm_ta_color ,
80
+ R .drawable .ic_wm_yes ,
81
+ R .drawable .ic_wm_yes_color
82
+ };
56
83
@ InjectView (R .id .tbActionBar )
57
84
protected Toolbar tbActionBar ;
58
85
@ InjectView (R .id .rlSurfaceLayout )
@@ -63,26 +90,10 @@ public class CameraMainActivityTest extends AppCompatActivity implements Texture
63
90
protected ImageView selfieButton ;
64
91
@ InjectView (R .id .camera_overlay )
65
92
protected CameraOverlayView cameraOverlayView ;
66
-
67
93
TextureView mTextureView ;
68
94
private Camera mCamera ;
69
-
70
95
private Camera .Size optimalSize ;
71
96
private int mCameraId ;
72
-
73
-
74
- private int [] mVoteBadges = new int []{R .drawable .ic_wm_vote_for_me ,
75
- R .drawable .ic_wm_vote_for_me_color ,
76
- R .drawable .ic_wm_yes_im_voting ,
77
- R .drawable .ic_wm_yes_im_voting_color ,
78
- R .drawable .ic_wm_we_voting ,
79
- R .drawable .ic_wm_we_voting_color ,
80
- R .drawable .ic_wm_ta ,
81
- R .drawable .ic_wm_ta_color ,
82
- R .drawable .ic_wm_yes ,
83
- R .drawable .ic_wm_yes_color
84
- };
85
-
86
97
private int mSelectedBadge = 0 ;
87
98
private float mPreviewScale ;
88
99
@@ -143,18 +154,22 @@ protected void onCreate(Bundle savedInstanceState) {
143
154
setContentView (R .layout .surface_camera_layout_test );
144
155
ButterKnife .inject (this );
145
156
157
+ if (((YesEqualityApplication ) getApplication ()).isVotingStarted ()) {
158
+ sVoteBadges = AllVoteBadges ;
159
+ }
160
+
146
161
tbActionBar .setTitle (R .string .app_name );
147
162
tbActionBar .setOnMenuItemClickListener (new Toolbar .OnMenuItemClickListener () {
148
163
@ Override
149
164
public boolean onMenuItemClick (MenuItem item ) {
150
165
switch (item .getItemId ()) {
151
166
case R .id .action_info :
152
- Intent infoIntent = new Intent (CameraMainActivityTest .this , MainActivity
167
+ Intent infoIntent = new Intent (CameraActivity .this , MainActivity
153
168
.class );
154
169
startActivity (infoIntent );
155
170
return true ;
156
171
case R .id .action_reminders :
157
- Intent reminderIntent = new Intent (CameraMainActivityTest .this ,
172
+ Intent reminderIntent = new Intent (CameraActivity .this ,
158
173
NotificationActivity .class );
159
174
startActivity (reminderIntent );
160
175
return true ;
@@ -203,19 +218,19 @@ public boolean onTouch(View v, MotionEvent event) {
203
218
});
204
219
205
220
206
- ivWaterMarkPic .setImageResource (mVoteBadges [mSelectedBadge ]);
221
+ ivWaterMarkPic .setImageResource (sVoteBadges [mSelectedBadge ]);
207
222
ivWaterMarkPic .setOnClickListener (new View .OnClickListener () {
208
223
@ Override
209
224
public void onClick (View v ) {
210
225
getSharedPreferences (Constants .PREFS_NAME , MODE_PRIVATE ).edit ().putBoolean
211
226
(Constants .WATERMARK_CLICKED , true ).apply ();
212
- if (mSelectedBadge >= mVoteBadges .length - 1 ) {
227
+ if (mSelectedBadge >= sVoteBadges .length - 1 ) {
213
228
mSelectedBadge = 0 ;
214
229
} else {
215
230
mSelectedBadge ++;
216
231
}
217
232
218
- ivWaterMarkPic .setImageResource (mVoteBadges [mSelectedBadge ]);
233
+ ivWaterMarkPic .setImageResource (sVoteBadges [mSelectedBadge ]);
219
234
ivWaterMarkPic .setVisibility (View .VISIBLE );
220
235
ivWaterMarkPic .addOnLayoutChangeListener (new View .OnLayoutChangeListener () {
221
236
@ Override
@@ -338,7 +353,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
338
353
mCamera .startPreview ();
339
354
340
355
} catch (Exception e ) {
341
- Log .d (TAG , "Error starting mCamera preview: " + e .getMessage ());
356
+ Log .d (this . getClass (). getSimpleName () , "Error starting mCamera preview: " + e .getMessage ());
342
357
}
343
358
}
344
359
@@ -415,18 +430,14 @@ void moveWaterMarkWithinBounds() {
415
430
ivWaterMarkPic .setX (0 );
416
431
} else if (rlSurfaceLayout .getWidth () - internalX < ivWaterMarkPic .getWidth () / 2 ) {
417
432
ivWaterMarkPic .setX (rlSurfaceLayout .getWidth () - ivWaterMarkPic .getWidth ());
418
- } /*else {
419
- ivWaterMarkPic.setX(internalX - (ivWaterMarkPic.getWidth() / 2));
420
- }*/
433
+ }
421
434
422
435
423
436
if (internalY < ivWaterMarkPic .getHeight () / 2 ) {
424
437
ivWaterMarkPic .setY (0 );
425
438
} else if (rlSurfaceLayout .getHeight () - internalY < ivWaterMarkPic .getHeight () / 2 ) {
426
439
ivWaterMarkPic .setY (rlSurfaceLayout .getHeight () - ivWaterMarkPic .getHeight ());
427
- } /*else {
428
- ivWaterMarkPic.setY(internalY - (ivWaterMarkPic.getHeight() / 2));
429
- }*/
440
+ }
430
441
}
431
442
432
443
@@ -483,7 +494,7 @@ public void saveAndSharePicture(Bitmap bitmap) {
483
494
} catch (IOException exception ) {
484
495
showSavingPictureErrorToast ();
485
496
486
- Log .w (TAG , "IOException during saving bitmap" , exception );
497
+ Log .w (this . getClass (). getSimpleName () , "IOException during saving bitmap" , exception );
487
498
return ;
488
499
}
489
500
@@ -555,6 +566,10 @@ public void onPictureTaken(byte[] data, Camera camera) {
555
566
}
556
567
557
568
569
+ if (sVoteBadges [mSelectedBadge ] == R .drawable .ic_wm_i_voted || sVoteBadges [mSelectedBadge ] == R .drawable .ic_wm_i_voted_color ) {
570
+ getSharedPreferences (Constants .PREFS_NAME , MODE_PRIVATE ).edit ().putBoolean (Constants .HAS_VOTED , true ).apply ();
571
+ }
572
+
558
573
Bitmap waterMark = ((BitmapDrawable ) ivWaterMarkPic .getDrawable ()).getBitmap ();
559
574
560
575
bitmap = BitmapUtils .cropBitmapToSquare (bitmap );
0 commit comments