4848import ie .yesequality .yesequality .utils .BitmapUtils ;
4949import ie .yesequality .yesequality .views .CameraOverlayView ;
5050
51- public class CameraMainActivityTest extends AppCompatActivity implements TextureView
51+ public class CameraActivity extends AppCompatActivity implements TextureView
5252 .SurfaceTextureListener ,
5353 Camera .PictureCallback {
54- public static final String TAG = "CameraMainActivity" ;
5554 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+ };
5683 @ InjectView (R .id .tbActionBar )
5784 protected Toolbar tbActionBar ;
5885 @ InjectView (R .id .rlSurfaceLayout )
@@ -63,26 +90,10 @@ public class CameraMainActivityTest extends AppCompatActivity implements Texture
6390 protected ImageView selfieButton ;
6491 @ InjectView (R .id .camera_overlay )
6592 protected CameraOverlayView cameraOverlayView ;
66-
6793 TextureView mTextureView ;
6894 private Camera mCamera ;
69-
7095 private Camera .Size optimalSize ;
7196 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-
8697 private int mSelectedBadge = 0 ;
8798 private float mPreviewScale ;
8899
@@ -143,18 +154,22 @@ protected void onCreate(Bundle savedInstanceState) {
143154 setContentView (R .layout .surface_camera_layout_test );
144155 ButterKnife .inject (this );
145156
157+ if (((YesEqualityApplication ) getApplication ()).isVotingStarted ()) {
158+ sVoteBadges = AllVoteBadges ;
159+ }
160+
146161 tbActionBar .setTitle (R .string .app_name );
147162 tbActionBar .setOnMenuItemClickListener (new Toolbar .OnMenuItemClickListener () {
148163 @ Override
149164 public boolean onMenuItemClick (MenuItem item ) {
150165 switch (item .getItemId ()) {
151166 case R .id .action_info :
152- Intent infoIntent = new Intent (CameraMainActivityTest .this , MainActivity
167+ Intent infoIntent = new Intent (CameraActivity .this , MainActivity
153168 .class );
154169 startActivity (infoIntent );
155170 return true ;
156171 case R .id .action_reminders :
157- Intent reminderIntent = new Intent (CameraMainActivityTest .this ,
172+ Intent reminderIntent = new Intent (CameraActivity .this ,
158173 NotificationActivity .class );
159174 startActivity (reminderIntent );
160175 return true ;
@@ -203,19 +218,19 @@ public boolean onTouch(View v, MotionEvent event) {
203218 });
204219
205220
206- ivWaterMarkPic .setImageResource (mVoteBadges [mSelectedBadge ]);
221+ ivWaterMarkPic .setImageResource (sVoteBadges [mSelectedBadge ]);
207222 ivWaterMarkPic .setOnClickListener (new View .OnClickListener () {
208223 @ Override
209224 public void onClick (View v ) {
210225 getSharedPreferences (Constants .PREFS_NAME , MODE_PRIVATE ).edit ().putBoolean
211226 (Constants .WATERMARK_CLICKED , true ).apply ();
212- if (mSelectedBadge >= mVoteBadges .length - 1 ) {
227+ if (mSelectedBadge >= sVoteBadges .length - 1 ) {
213228 mSelectedBadge = 0 ;
214229 } else {
215230 mSelectedBadge ++;
216231 }
217232
218- ivWaterMarkPic .setImageResource (mVoteBadges [mSelectedBadge ]);
233+ ivWaterMarkPic .setImageResource (sVoteBadges [mSelectedBadge ]);
219234 ivWaterMarkPic .setVisibility (View .VISIBLE );
220235 ivWaterMarkPic .addOnLayoutChangeListener (new View .OnLayoutChangeListener () {
221236 @ Override
@@ -338,7 +353,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
338353 mCamera .startPreview ();
339354
340355 } 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 ());
342357 }
343358 }
344359
@@ -415,18 +430,14 @@ void moveWaterMarkWithinBounds() {
415430 ivWaterMarkPic .setX (0 );
416431 } else if (rlSurfaceLayout .getWidth () - internalX < ivWaterMarkPic .getWidth () / 2 ) {
417432 ivWaterMarkPic .setX (rlSurfaceLayout .getWidth () - ivWaterMarkPic .getWidth ());
418- } /*else {
419- ivWaterMarkPic.setX(internalX - (ivWaterMarkPic.getWidth() / 2));
420- }*/
433+ }
421434
422435
423436 if (internalY < ivWaterMarkPic .getHeight () / 2 ) {
424437 ivWaterMarkPic .setY (0 );
425438 } else if (rlSurfaceLayout .getHeight () - internalY < ivWaterMarkPic .getHeight () / 2 ) {
426439 ivWaterMarkPic .setY (rlSurfaceLayout .getHeight () - ivWaterMarkPic .getHeight ());
427- } /*else {
428- ivWaterMarkPic.setY(internalY - (ivWaterMarkPic.getHeight() / 2));
429- }*/
440+ }
430441 }
431442
432443
@@ -483,7 +494,7 @@ public void saveAndSharePicture(Bitmap bitmap) {
483494 } catch (IOException exception ) {
484495 showSavingPictureErrorToast ();
485496
486- Log .w (TAG , "IOException during saving bitmap" , exception );
497+ Log .w (this . getClass (). getSimpleName () , "IOException during saving bitmap" , exception );
487498 return ;
488499 }
489500
@@ -555,6 +566,10 @@ public void onPictureTaken(byte[] data, Camera camera) {
555566 }
556567
557568
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+
558573 Bitmap waterMark = ((BitmapDrawable ) ivWaterMarkPic .getDrawable ()).getBitmap ();
559574
560575 bitmap = BitmapUtils .cropBitmapToSquare (bitmap );
0 commit comments