-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTestBrainReboot.java
1708 lines (1621 loc) · 79.6 KB
/
TestBrainReboot.java
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.taozen.quithabit;
import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.anupcowkur.herebedragons.SideEffect;
import com.budiyev.android.circularprogressbar.CircularProgressBar;
import com.github.javiersantos.bottomdialogs.BottomDialog;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.shashank.sony.fancygifdialoglib.FancyGifDialog;
import com.shashank.sony.fancygifdialoglib.FancyGifDialogListener;
import com.taozen.quithabit.cardActivities.AchievmentsActivity;
import com.taozen.quithabit.cardActivities.FailLogsActivity;
import com.taozen.quithabit.optionsMenuActivities.AboutActivity;
import com.taozen.quithabit.cardActivities.ChallengeActivity;
import com.taozen.quithabit.cardActivities.SavingsActivity;
import com.taozen.quithabit.utils.MyHttpManager;
import com.transitionseverywhere.ArcMotion;
import com.transitionseverywhere.ChangeBounds;
import com.transitionseverywhere.TransitionManager;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Objects;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import butterknife.BindView;
import butterknife.ButterKnife;
import pl.bclogic.pulsator4droid.library.PulsatorLayout;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.CHALLENGES_STRING;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.CLICKED;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.COUNTER;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.DAYOFPRESENT;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.HOUR_OF_FIRSLAUNCH_SP;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.INITIAL_CIGG_PER_DAY;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.LIFEREGAINED;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.MODIFIED_CIGG_PER_DAY;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.CLICKDAY_SP;
import static com.taozen.quithabit.utils.Constants.SharedPreferences.SAVINGS_FINAL;
public class TestBrainReboot extends AppCompatActivity {
String arr = "";
public static final String HTTPS_PYFLASKTAO_HEROKUAPP_COM_BOOKS = "https://pyflasktao.herokuapp.com/books";
boolean higherThanOne;
private List<MainActivity.MyAsyncTask> tasks;
private Timer timer;
Float lifeRegained;
// private int lifeRegainedInteger;
//dialogs for fabs - messages
private String normalMessageForDialog = "\"Did you abstained to smoke today ?\"";
private String moreThanOneDayPassedMessageForDialog = "Did you abstained to smoke in the last days ?";
private String firstMessageDialog = "Hello, this is your first day!\nSince you're here " +
"it means that you made the first step in order to get rid of your habit";
//TODO - ask user how many cigarettes smokes per day with dialog
private int cigarettesPerDay;
//Views
@BindView(android.R.id.content) View parentLayout;
//Fab
@BindView(R.id.fab) FloatingActionButton fab;
//CardViews
@BindView(R.id.progressCardIdProgress) CardView progressCardView;
@BindView(R.id.progressCardIdSavings) CardView savingsCardView;
@BindView(R.id.progressCardIdChallenge) CardView challengeCardView;
@BindView(R.id.progressCardIdLogs) CardView timeStampLogsCardview;
@BindView(R.id.card_view_mainID) CardView cardViewMain;
@BindView(R.id.progressCardIdAchievments) CardView achievementRanksCard;
@BindView(R.id.progressCardId) CardView upperProgressPercentsCard;
//TextViews
// @BindView(R.id.rankFourIdText) TextView rankFourTxt;
// @BindView(R.id.rankThreeIdText) TextView rankThreeTxt;
// @BindView(R.id.rankTwoIdText) TextView rankTwoTxt;
// @BindView(R.id.rankOneIdText) TextView rankOneTxt;
@BindView(R.id.rank_master) TextView rank_masterTxt;
@BindView(R.id.toolbar_subtitle) TextView subTextToolbar;
@BindView(R.id.counterTextId) TextView counterText;
@BindView(R.id.txtProgressIdForGums) TextView txtProgressForGums;
@BindView(R.id.txtProgressIdForBreath) TextView txtProgressForBreath;
@BindView(R.id.txtProgressIdForFatigue) TextView txtProgressForFatigue;
@BindView(R.id.txtProgressIdForEnergy) TextView txtProgressForEnergyLevels;
@BindView(R.id.targetTxtViewId) TextView targetTxtViewId;
@BindView(R.id.moneyortimeId) TextView moneyOrTimeTextView;
@BindView(R.id.remaining_days_Id) TextView remainingDaysTxt;
@BindView(R.id.tipofthedayTxtViewId) TextView tipofthedayTxtView;
@BindView(R.id.progressActivityId) TextView progressBarsTxt;
@BindView(R.id.logsTxtId) TextView failLogsTxtView;
@BindView(R.id.challengeTxtIdTitleId) TextView challengeTextViewTitle;
@BindView(R.id.challengeTextId) TextView challengeTextViewSubtitle;
@BindView(R.id.tvErrorId) TextView errorText;
@BindView(R.id.textNonSmokerId) TextView textNonSmoker;
@BindView(R.id.subTextSmokeId) TextView subTextNonSmoker;
@BindView(R.id.subTextEnergyId) TextView subTextEnergy;
@BindView(R.id.subTextBreathId) TextView subTextBreath;
@BindView(R.id.subTextFatigueId) TextView subTextFatigue;
@BindView(R.id.subTextGumsId) TextView subTextGums;
@BindView(R.id.YourAchievmentsId) TextView yourAchievmentTxt;
@BindView(R.id.YourProgressId) TextView yourProgressTxt;
@BindView(R.id.YourSavingsId) TextView yourSavingsTxt;
@BindView(R.id.YourLogsId) TextView yourLogsTxt;
@BindView(R.id.YourProgressIdCigaretes) TextView userCigaretesProgressTxt;
@BindView(R.id.YourProgressIdRank) TextView userRankProgressTxt;
@BindView(R.id.YourProgressIdHours) TextView userHoursProgressTxt;
//ProgressBar
@BindView(R.id.loadingProgressId) ProgressBar progressBarLoading;
@BindView(R.id.loadingProgressId2) ProgressBar progressBarLoading2;
//ImageViews
@BindView(R.id.counterImageId) ImageView counterImgView;
@BindView(R.id.rankOneId) ImageView rankOneImg;
@BindView(R.id.rankTwoId) ImageView rankTwoImg;
@BindView(R.id.rankThreeId) ImageView rankThreeImg;
@BindView(R.id.rankFourId) ImageView rankFourImg;
@BindView(R.id.backgroundId) ImageView backgroundImgWall;
// @BindView(R.id.imageViewMiddleId) ImageView imageViewMiddle;
@BindView(R.id.pulsator) PulsatorLayout pulsator;
//firstStart bool
boolean isFirstStart;
//counter for user
private int counter;
private long savings = 0;
private int DAY_OF_CLICK = 0,
DAY_OF_PRESENT = 0,
HOUR_OF_DAYLIGHT = 0,
HOUR_OF_FIRSTLAUNCH = 0;
//wil start from 30 to 60 to 90
private int userMaxCountForHabit = -1;
//default false
private boolean buttonClickedToday;
//Toolbar
private Toolbar toolbar;
//Calendar
private Calendar calendarOnClick,
calendarForProgress;
//shared pref
private SharedPreferences preferences;
private SharedPreferences.Editor editor;
//circular progressbar
private CircularProgressBar progressBarEnergyLevel,
progressBarGumsLevel,
progressBarFatigueLevel,
progressBarBreathlevel;
private DisplayMetrics metrics = new DisplayMetrics();
private Configuration config;
private String challs;
private StringBuilder strBuilder = new StringBuilder();
//fonts
static Typeface montSerratBoldTypeface;
static Typeface montSerratItallicTypeface;
static Typeface montSerratLightTypeface;
static Typeface montSerratMediumTypeface;
static Typeface montSerratSemiBoldTypeface;
static Typeface montSerratExtraBoldTypeface;
static Typeface montSerratSimpleBoldTypeface;
DecimalFormat numberFormat;
ObjectAnimator anim,anim2;
int i = 1;
MainActivity.MyAsyncTask task;
// public static void main(String[] args) {
// DecimalFormat a = new DecimalFormat("#.##");
// if (a instanceof DecimalFormat) {
// System.out.println("yes it is object animator");
// }
// }
//OnCreate [START]
@SuppressLint("CommitPrefEdits")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(MainActivity.this);
//shared pref
preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
editor = preferences.edit();
startFirstActivity();
Intent intent = getIntent();
String name = intent.getStringExtra("data");
tipofthedayTxtView.setText(name);
numberFormat = new DecimalFormat("#.##");
//anim for subtext
anim = ObjectAnimator.ofInt(subTextNonSmoker,
"TextColor",
Color.WHITE, getResources().getColor(R.color.greish),
getResources().getColor(R.color.greish));
anim.setDuration(1200);
anim.setEvaluator(new ArgbEvaluator());
anim.setRepeatMode(ValueAnimator.RESTART);
anim.setRepeatCount(Animation.INFINITE);
//anim for counter
anim2 = ObjectAnimator.ofInt(counterText,
"TextColor",
Color.WHITE, getResources().getColor(R.color.colorPrimary),
Color.WHITE);
anim2.setDuration(1500);
anim2.setEvaluator(new ArgbEvaluator());
anim2.setRepeatMode(ValueAnimator.REVERSE);
anim2.setRepeatCount(Animation.INFINITE);
//testing area
Date date = new Date();
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(date);
HOUR_OF_DAYLIGHT = calendar.get(Calendar.HOUR_OF_DAY);
setTheHourOfFirstLaunch(calendar);
setBackgroundForDaylightOrNight();
tasks = new ArrayList<>();
config = getResources().getConfiguration();
//set text for checkin
setCheckInText();
//color of the FAB - NOW IS already changed in XML
//fab.setBackgroundTintList(ColorStateList.valueOf(Color.WHITE));
getWindowManager().getDefaultDisplay().getMetrics(metrics);
//CONDITION TO SET TARGET TEXT AFTER CHECKINNG COUNTER
if (preferences.contains(COUNTER)){ counter = preferences.getInt(COUNTER, -1);counterText.setText(String.valueOf(counter)); }
if (preferences.contains(INITIAL_CIGG_PER_DAY)){cigarettesPerDay = preferences.getInt(INITIAL_CIGG_PER_DAY, 0);}
if (preferences.contains(LIFEREGAINED)){ lifeRegained = preferences.getFloat(LIFEREGAINED, 0); }
setTargetDays();
firstCheckMax();
getWindow().setStatusBarColor(ContextCompat.getColor(MainActivity.this, R.color.white));
progressBarLoading.getIndeterminateDrawable().setColorFilter(
getResources().getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_IN);
progressBarLoading2.getIndeterminateDrawable().setColorFilter(
getResources().getColor(R.color.colorPrimaryDark), PorterDuff.Mode.SRC_IN);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayShowTitleEnabled(false);
// getSupportActionBar().setElevation(0); //remove shadow - but now it is already removed in xml file
progressCardView.setCardElevation(0);
savingsCardView.setCardElevation(0);
timeStampLogsCardview.setCardElevation(0);
cardViewMain.setCardElevation(0);
achievementRanksCard.setCardElevation(0);
challengeCardView.setCardElevation(0);
upperProgressPercentsCard.setCardElevation(0);
//progress for percent - this is a circular bar
progressBarEnergyLevel = findViewById(R.id.progress_bar_energy);
progressBarFatigueLevel = findViewById(R.id.progress_bar_fatigue);
progressBarBreathlevel = findViewById(R.id.progress_bar_breath);
progressBarGumsLevel = findViewById(R.id.progress_bar_gums);
//setMargin
setMarginForProgress();
//check online state
// checkActivityOnline();
setTxtViewForUserMaxCountDaysOnStringVersion(
String.valueOf(userMaxCountForHabit),
R.string.target_string, targetTxtViewId);
montSerratBoldTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Black.ttf");
montSerratItallicTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Italic.ttf");
montSerratLightTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Light.ttf");
montSerratMediumTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Medium.ttf");
montSerratSemiBoldTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-SemiBold.ttf");
montSerratExtraBoldTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-ExtraBold.ttf");
montSerratSimpleBoldTypeface = Typeface.createFromAsset(getAssets(), "fonts/Montserrat-Bold.ttf");
counterText.setTypeface(montSerratBoldTypeface);
// targetTxtViewId.setTypeface(montSerratMediumTypeface);
// remainingDaysTxt.setTypeface(montSerratMediumTypeface);
remainingDaysTxt.setTypeface(montSerratSimpleBoldTypeface);
targetTxtViewId.setTypeface(montSerratSimpleBoldTypeface);
tipofthedayTxtView.setTypeface(montSerratItallicTypeface);
txtProgressForEnergyLevels.setTypeface(montSerratBoldTypeface);
txtProgressForFatigue.setTypeface(montSerratBoldTypeface);
txtProgressForBreath.setTypeface(montSerratBoldTypeface);
txtProgressForGums.setTypeface(montSerratBoldTypeface);
moneyOrTimeTextView.setTypeface(montSerratSimpleBoldTypeface);
challengeTextViewTitle.setTypeface(montSerratSimpleBoldTypeface);
challengeTextViewSubtitle.setTypeface(montSerratLightTypeface);
progressBarsTxt.setTypeface(montSerratBoldTypeface);
failLogsTxtView.setTypeface(montSerratLightTypeface);
textNonSmoker.setTypeface(montSerratBoldTypeface);
subTextEnergy.setTypeface(montSerratMediumTypeface);
subTextBreath.setTypeface(montSerratMediumTypeface);
subTextFatigue.setTypeface(montSerratMediumTypeface);
subTextGums.setTypeface(montSerratMediumTypeface);
yourAchievmentTxt.setTypeface(montSerratSimpleBoldTypeface);
yourProgressTxt.setTypeface(montSerratSimpleBoldTypeface);
yourSavingsTxt.setTypeface(montSerratSimpleBoldTypeface);
yourLogsTxt.setTypeface(montSerratSimpleBoldTypeface);
userCigaretesProgressTxt.setTypeface(montSerratLightTypeface);
userRankProgressTxt.setTypeface(montSerratLightTypeface);
userHoursProgressTxt.setTypeface(montSerratLightTypeface);
subTextNonSmoker.setTypeface(montSerratMediumTypeface);
subTextToolbar.setTypeface(montSerratSemiBoldTypeface);
rank_masterTxt.setTypeface(montSerratMediumTypeface);
// rankFourTxt.setTypeface(montSerratMediumTypeface);
// rankThreeTxt.setTypeface(montSerratMediumTypeface);
// rankTwoTxt.setTypeface(montSerratMediumTypeface);
// rankOneTxt.setTypeface(montSerratMediumTypeface);
int tvWidth = subTextNonSmoker.getWidth();
int tvHeight = subTextNonSmoker.getHeight();
float density = getResources().getDisplayMetrics().density;
float densityWidth = tvWidth / density;
float densityHeight = tvHeight / density;
Log.d("DENS", "widht: " + densityWidth + " height: " + densityHeight + density);
try {
if (preferences.contains(COUNTER)){
counter = preferences.getInt(COUNTER, -1);
}
//setting the achievments images for user
showEntireProgressForUserCard(userCigaretesProgressTxt, userRankProgressTxt, userHoursProgressTxt);
setImagesForAchievementCard();
setImprovementProgressLevels();
} catch (NullPointerException e) {
e.printStackTrace();
}
achievementRanksCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, AchievmentsActivity.class);
startActivity(intent);
}
});//achievementRanksCard[END]
timeStampLogsCardview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//TODO: finish logs activity
Intent intent = new Intent(MainActivity.this, FailLogsActivity.class);
startActivity(intent);
}
});//timeStampCardView[END]
savingsCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SavingsActivity.class);
intent.putExtra(SAVINGS_FINAL, savings);
startActivity(intent);
}
});//savingsCardView[END]
challengeCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ChallengeActivity.class);
startActivity(intent);
challs = "Tap to see your progress for your challenge!";
editor.putString(CHALLENGES_STRING, challs);
editor.apply();
}
});//challengeCardView[END]
//retrieving the counter and minute values
try {
//run the task
runningInBackground();
//counter on click for fab button
counterFabButtonInitializer();
setTargetDays();
moneyOrTimeAndGetAndSetValue();
if (preferences.contains(COUNTER)){
counter = preferences.getInt(COUNTER, -1);
}
if (preferences.contains(CLICKED)){
buttonClickedToday = preferences.getBoolean(CLICKED, false);
}
setImprovementProgressLevels();
} catch (NullPointerException e) {
e.printStackTrace();
}//[END OF RETRIEVING VALUES]
//milestone dialog ------------
// AlertDialog.Builder milestoneAlert = new AlertDialog.Builder(this);
// final EditText editTextForMilestone = new EditText(MainActivity.this);
// milestoneAlert.setMessage("Set your milestone ?");
// milestoneAlert.setTitle("Milestone!");
// milestoneAlert.setView(editTextForMilestone);
// milestoneAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int whichButton) {
// //What ever you want to do with the value
//// Editable milestone = editTextForMilestone.getText();
// String getMilestone = editTextForMilestone.getText().toString();
// userMaxCount = Integer.parseInt(getMilestone);
//
// }
// });
// milestoneAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int whichButton) {
// //do nothing
// }
// });
// milestoneAlert.show();
//choose your habit ------------
// AlertDialog.Builder habitAlert = new AlertDialog.Builder(this);
// final EditText editTextForChoosingHabit = new EditText(MainActivity.this);
// habitAlert.setMessage("Type your habit ?");
// habitAlert.setTitle("Habit!");
// habitAlert.setView(editTextForChoosingHabit);
// habitAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int whichButton) {
// //What ever you want to do with the value
//// Editable habit = editTextForChoosingHabit.getText();
// habitString = editTextForChoosingHabit.getText().toString();
//
// }
// });
// habitAlert.setNegativeButton("No", new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int whichButton) {
// //do nothing
// }
// });
// habitAlert.show();
// //dialog ------------
// new BottomDialog.Builder(this)
// .setTitle("Awesome!")
// .setContent("What can we improve? Your feedback is always welcome.")
// .setPositiveText("OK")
// .setPositiveBackgroundColorResource(R.color.colorPrimary)
// //.setPositiveBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)
// .setPositiveTextColorResource(android.R.color.white)
// //.setPositiveTextColor(ContextCompat.getColor(this, android.R.color.colorPrimary)
// .onPositive(new BottomDialog.ButtonCallback() {
// @Override
// public void onClick(BottomDialog dialog) {
// Log.d("BottomDialogs", "Do something!");
// }
// }).show();
//fancy dialog gif ------------
// new FancyGifDialog.Builder(this)
// .setTitle("Granny eating chocolate dialog box")
// .setMessage("This is a granny eating chocolate dialog box. This library is used to help you easily create fancy gify dialog.")
// .setNegativeBtnText("Cancel")
// .setPositiveBtnBackground("#FF4081")
// .setPositiveBtnText("Ok")
// .setNegativeBtnBackground("#FFA9A7A8")
// .setGifResource(R.drawable.braingif) //Pass your Gif here
// .isCancellable(true)
// .OnPositiveClicked(new FancyGifDialogListener() {
// @Override
// public void OnClick() {
// Toast.makeText(MainActivity.this,"Ok",Toast.LENGTH_SHORT).show();
// }
// })
// .OnNegativeClicked(new FancyGifDialogListener() {
// @Override
// public void OnClick() {
// Toast.makeText(MainActivity.this,"Cancel",Toast.LENGTH_SHORT).show();
// }
// })
// .build();
}//[END OF ONCREATE]
private void setTheHourOfFirstLaunch(Calendar calendar) {
//my personal method to save a value and keep it every time i launch on create :)
if (preferences.contains(HOUR_OF_FIRSLAUNCH_SP)) {
HOUR_OF_FIRSTLAUNCH = preferences.getInt(HOUR_OF_FIRSLAUNCH_SP, -1);
Log.d("TAOZEN1", "share prefs contains: firsthour = " + HOUR_OF_FIRSTLAUNCH);
} else {
Log.d("TAOZEN1", "share prefs DOES NOT contains: firsthour");
HOUR_OF_FIRSTLAUNCH = calendar.get(Calendar.HOUR_OF_DAY);
editor.putInt(HOUR_OF_FIRSLAUNCH_SP, HOUR_OF_FIRSTLAUNCH);
editor.apply();
strBuilder.append(String.format(getString(R.string.checkinStr), HOUR_OF_FIRSTLAUNCH));
strBuilder.append("\nWe will start tutorial now.");
// showCustomDialogOnFirstLaunch("Welcome", strBuilder);
}
}
@SideEffect
private void setBackgroundForDaylightOrNight() {
//change wallpaper during nighttime
if (HOUR_OF_DAYLIGHT <= 6 || HOUR_OF_DAYLIGHT >= 22) {
// if (HOUR_OF_DAYLIGHT >= 6 && HOUR_OF_DAYLIGHT <= 20) {
backgroundImgWall.setBackgroundResource(R.drawable.ppp);
tipofthedayTxtView.setTextColor(getResources().getColor(R.color.white));
tipofthedayTxtView.setAlpha(0.8f);
counterText.setTextColor(getResources().getColor(R.color.white));
counterText.setAlpha(1.0f);
remainingDaysTxt.setTextColor(getResources().getColor(R.color.white));
remainingDaysTxt.setAlpha(0.8f);
targetTxtViewId.setTextColor(getResources().getColor(R.color.white));
targetTxtViewId.setAlpha(0.8f);
textNonSmoker.setTextColor(getResources().getColor(R.color.white));
textNonSmoker.setAlpha(1.0f);
// subTextNonSmoker.setTextColor(getResources().getColor(R.color.greish));
subTextNonSmoker.setBackground(getResources().getDrawable(R.drawable.custom_button_round));
subTextNonSmoker.setAlpha(1.0f);
backgroundImgWall.setAlpha(1.0f);
} else {
//change wallpaper during daytime
backgroundImgWall.setBackgroundResource(R.drawable.bgday);
tipofthedayTxtView.setTextColor(getResources().getColor(R.color.greish));
counterText.setTextColor(getResources().getColor(R.color.greish));
remainingDaysTxt.setTextColor(getResources().getColor(R.color.greish));
targetTxtViewId.setTextColor(getResources().getColor(R.color.greish));
textNonSmoker.setTextColor(getResources().getColor(R.color.greish));
textNonSmoker.setAlpha(0.8f);
// subTextNonSmoker.setTextColor(getResources().getColor(R.color.greish));
subTextNonSmoker.setBackground(getResources().getDrawable(R.drawable.custom_button_round));
subTextNonSmoker.setAlpha(0.7f);
// backgroundImgWall.setAlpha(0.05f);
backgroundImgWall.setAlpha(0f);
}
}
private void firstCheckMax() {
if (userMaxCountForHabit == -1) {
userMaxCountForHabit = 30;
editor.putInt(getString(R.string.maxCounter), userMaxCountForHabit);
editor.apply();
} else {
userMaxCountForHabit = preferences.getInt(getString(R.string.maxCounter), -1);
}
}
//dialog when user pass a day
private void positiveDialogAfterPassDay() {
//dialog ------------
new BottomDialog.Builder(this)
.setTitle("Awesome!")
.setContent("What can we improve? Your feedback is always welcome.")
.setPositiveText("OK")
.setPositiveBackgroundColorResource(R.color.colorPrimary)
//.setPositiveBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)
.setPositiveTextColorResource(android.R.color.white)
//.setPositiveTextColor(ContextCompat.getColor(this, android.R.color.colorPrimary)
.onPositive(new BottomDialog.ButtonCallback() {
@Override
public void onClick(BottomDialog dialog) {
//call on destroy
// finish();
Log.d("BottomDialogs", "Do something!");
}
}).show();
}
// //dialog when user pass a day
// private void showCustomDialogOnFirstLaunch(String title, StringBuilder content){
// //dialog ------------
// new BottomDialog.Builder(this)
// .setTitle(title)
// .setContent(content)
// .setPositiveText("OK")
// .setCancelable(false)
// .setPositiveBackgroundColorResource(R.color.colorPrimary)
// //.setPositiveBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)
// .setPositiveTextColorResource(android.R.color.white)
// //.setPositiveTextColor(ContextCompat.getColor(this, android.R.color.colorPrimary)
// .onPositive(new BottomDialog.ButtonCallback() {
// @Override
// public void onClick(BottomDialog dialog) {
// Log.d("BottomDialogs", "Do something!");
// //intro activity check in a separate thread
//// startIntroActivity();
//// showDialogForSavingSum();
// }
// }).show();
// }
//dialog when user pass a day
private void negativeDialogAfterRelapse() {
//dialog ------------
new BottomDialog.Builder(this)
.setTitle("It's ok to fail!")
.setContent("What can we improve? Your feedback is always welcome.")
.setPositiveText("OK")
.setCancelable(false)
.setPositiveBackgroundColorResource(R.color.colorPrimary)
//.setPositiveBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary)
.setPositiveTextColorResource(android.R.color.white)
//.setPositiveTextColor(ContextCompat.getColor(this, android.R.color.colorPrimary)
.onPositive(new BottomDialog.ButtonCallback() {
@Override
public void onClick(BottomDialog dialog) {
Log.d("BottomDialogs", "Do something!");
}
}).show();
}
// @SideEffect
// private void startIntroActivity() {
// //intro
// //code for INTRO
// Thread threadForSlider = new Thread(new Runnable() {
// @Override
// public void run() {
//// // Create a new boolean and preference and set it to true
//// Log.d("taozenD", "thread separat: " + Thread.currentThread().getName());
//// if (preferences.contains("firstStart")) {
//// isFirstStart = preferences.getBoolean("firstStart", false);
//// } else {
//// //on first launch this will trigger
//// isFirstStart = true;
//// editor.putBoolean("firstStart", false);
//// editor.apply();
//// }
//// // If the activity has never started before...
// if (isFirstStart) {
//// if (preferences.contains(COUNTER)) {
//// counter = preferences.getInt(COUNTER, -1);
//// editor.putInt(COUNTER, counter);
//// editor.apply();
//// }
// // Launch app intro
// final Intent i = new Intent(MainActivity.this, IntroActivity.class);
// runOnUiThread(new Runnable() {
// @Override public void run() {
// Log.d("taozenD", "thread din ui: " + Thread.currentThread().getName());
// startActivity(i);
// }
// });
// }
// }
// });
// threadForSlider.start();
// }//end of INTRO
@SideEffect
private void startFirstActivity() {
//intro
//code for INTRO
Thread threadForSlider = new Thread(new Runnable() {
@Override
public void run() {
// Create a new boolean and preference and set it to true
Log.d("taozenD", "thread separat: " + Thread.currentThread().getName());
if (preferences.contains("firstStart")) {
isFirstStart = preferences.getBoolean("firstStart", false);
} else {
//on first launch this will trigger
isFirstStart = true;
editor.putBoolean("firstStart", false);
editor.apply();
//fake first day of user to be day of present -1 to enable him/her to check in for the first time
//[calendar area]
calendarForProgress = Calendar.getInstance();
calendarForProgress.setTimeZone(TimeZone.getTimeZone("GMT+2"));
DAY_OF_PRESENT = calendarForProgress.get(Calendar.DAY_OF_YEAR);
DAY_OF_CLICK = DAY_OF_PRESENT - 1;
editor.putInt(CLICKDAY_SP, DAY_OF_CLICK);
editor.apply();
Log.d("DAYOFTAOZEN", DAY_OF_CLICK + " ");
}
// If the activity has never started before...
if (isFirstStart) {
if (preferences.contains(COUNTER)) {
counter = preferences.getInt(COUNTER, -1);
editor.putInt(COUNTER, counter);
editor.apply();
}
// Launch app intro
final Intent i = new Intent(MainActivity.this, FirstScreenActivity.class);
runOnUiThread(new Runnable() {
@Override public void run() {
Log.d("taozenD", "thread din ui: " + Thread.currentThread().getName());
startActivity(i);
// startIntroActivity();
}
});
}
}
});
threadForSlider.start();
}//end of INTRO
@SideEffect
private void counterFabButtonInitializer() {
//active when user passed a day
//inactive when user wait
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (preferences.contains(COUNTER)){
counter = preferences.getInt(COUNTER, -1);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
buttonClickedToday = true;
editor.putBoolean(CLICKED, buttonClickedToday);
editor.apply();
cigarettesPerDay = preferences.getInt(INITIAL_CIGG_PER_DAY, 0);
//[calendar area]
calendarOnClick = Calendar.getInstance();
calendarOnClick.setTimeZone(TimeZone.getTimeZone("GMT+2"));
DAY_OF_CLICK = calendarOnClick.get(Calendar.DAY_OF_YEAR);
editor.putInt(CLICKDAY_SP, DAY_OF_CLICK);
editor.apply();
setImagesForAchievementCard();
Log.d("INTROTAO", "counter from onclick = " + counter + buttonClickedToday);
String messageForDialog = "";
messageForDialog = higherThanOne ? moreThanOneDayPassedMessageForDialog : normalMessageForDialog;
//between 1 and 29
if (counter == 0) {
normalFancyDialog("WELCOME TO QUIT HABIT!", firstMessageDialog);
} else if (counter > 0 && counter < 29) {
normalFancyDialog("BEAT YOUR MILESTONE - 30 DAYS!", messageForDialog);
//between 29(to show up in 30) and 60
} else if (counter > 28 && counter < 59) {
normalFancyDialog("BEAT YOUR MILESTONE - 60 DAYS!", messageForDialog);
//between 59(to show up in 60) and 90
} else if (counter > 58 && counter < 91) {
normalFancyDialog("BEAT YOUR MILESTONE - 90 DAYS!", messageForDialog);
//SHOW FANCY TOAST WITH CONGRATS
}//[END OF ELSE IFS DIALOGS]
fab.hide();
anim.cancel();
subTextNonSmoker.setTextColor(getResources().getColor(R.color.greish));
}
});
}
private void normalFancyDialog(String title, String message) {
new FancyGifDialog.Builder(MainActivity.this)
.setTitle(title)
.setMessage(message)
.setNegativeBtnText("NO")
.setPositiveBtnBackground("#FF4081")
.setPositiveBtnText("YES")
.setNegativeBtnBackground("#FFA9A7A8")
.setGifResource(R.drawable.source) //Pass your Gif here
.isCancellable(false)
.OnPositiveClicked(new FancyGifDialogListener() {
@Override
public void OnClick() {
setCheckInText();
if (counter == 0) {
savings = preferences.getLong("taoz10", -10);
} else {
savings = savings + preferences.getLong("taoz10", 0);
}
if (preferences.contains("diff") && higherThanOne){
Log.d("COUNTERTAO", "before - counter is raised with: " + counter);
counter = counter + preferences.getInt("diff", -100);
Log.d("COUNTERTAO", "after - counter is raised with: " + counter);
higherThanOne = false;
} else {
Log.d("COUNTERTAO", "before - counter is raised with: " + counter);
counter++;
higherThanOne = false;
Log.d("COUNTERTAO", "after - counter is raised with: " + counter);
}
i = 1;
editor.putInt(COUNTER, counter);
int tempCigarettes = cigarettesPerDay * counter;
userCigaretesProgressTxt.setText("Ciggaretes not smoked: " + tempCigarettes);
editor.putInt(MODIFIED_CIGG_PER_DAY, tempCigarettes);
lifeRegained = Float.valueOf((5f * Float.valueOf(tempCigarettes)) / 60f);
userHoursProgressTxt.setText("Life regained: " + numberFormat.format(lifeRegained) + " hours");
editor.putFloat(LIFEREGAINED, lifeRegained);
editor.putLong(SAVINGS_FINAL, savings);
editor.apply();
checkActivityOnline();
// setTheSavingsPerDay();
moneyOrTimeAndGetAndSetValue();
setImprovementProgressLevels();
setImagesForAchievementCard();
counterText.setText(String.valueOf(counter));
setTargetDays();
// showEntireProgressForUserCard(userCigaretesProgressTxt, userRankProgressTxt, userHoursProgressTxt);
// Toast.makeText(MainActivity.this,"Ok",Toast.LENGTH_SHORT).show();
//var 1 - dialog after answer
positiveDialogAfterPassDay();
//var 2 - custom toast after answer
// FancyToast.makeText(MainActivity.this, "Congratulations! One day healthier than yesterday!",
// 20, FancyToast.SUCCESS, true).show();
}
})
.OnNegativeClicked(new FancyGifDialogListener() {
@Override
public void OnClick() {
i = 1;
//get time of relapse and put it into arraylist to send in logs activity
Calendar calendarOnClick2 = Calendar.getInstance();
calendarOnClick2.setTimeZone(TimeZone.getTimeZone("GMT+2"));
String tem = calendarOnClick2.getTime().toString() + " ole\n";
if (preferences.contains("arr")){
arr = tem + preferences.getString("arr", "no value");
} else {
arr = tem;
}
editor.putString("arr", arr);
editor.apply();
counter = 0;
savings = 0;
//to see
editor.putLong(SAVINGS_FINAL, savings);//off
//maybe
editor.putInt(COUNTER, counter);
//new edit
int tempCigarettes = preferences.getInt(INITIAL_CIGG_PER_DAY, 0);
userCigaretesProgressTxt.setText("Ciggaretes not smoked: " + tempCigarettes);
editor.putInt(MODIFIED_CIGG_PER_DAY, tempCigarettes);
lifeRegained = Float.valueOf((5f * Float.valueOf(tempCigarettes)) / 60f);
userHoursProgressTxt.setText("Life regained: " + numberFormat.format(lifeRegained) + " hours");
editor.putFloat(LIFEREGAINED, lifeRegained);
editor.apply();
checkActivityOnline();
// setTheSavingsPerDay();
moneyOrTimeAndGetAndSetValue();
setImprovementProgressLevels();
try {
counter = preferences.getInt(COUNTER, -1);
} catch (NullPointerException e) {
e.printStackTrace();
}
counterText.setText(String.valueOf(counter));
setTargetDays();
// showEntireProgressForUserCard(userCigaretesProgressTxt, userRankProgressTxt, userHoursProgressTxt);
// Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
negativeDialogAfterRelapse();
}
})
.build();//[END of NORMAL DIALOG]
}
private void setTxtViewForUserSavingValueOfMoneyOrTime(
String string,
int androiId, TextView textView) {
DecimalFormat formatter = new DecimalFormat("###,###,##0.00");
String value = formatter.format(Integer.parseInt(string)*365);
//target counter string
String finalS = getString(androiId, string) + "\nper year: " + value + "$";
textView.setText(finalS);
}
private void setTxtViewForUserMaxCountDaysOnStringVersion(
String string,
int androiId,
TextView textview) {
//target counter string
textview.setText(getString(androiId, string));
}
private void moneyOrTimeAndGetAndSetValue() {
if (preferences.contains(SAVINGS_FINAL)) {
try {
savings = preferences.getLong(SAVINGS_FINAL, 1);
} catch (ClassCastException e) {
e.printStackTrace();
}
} else {
savings = 0;
editor.putLong(SAVINGS_FINAL, savings);
editor.apply();
}
setTxtViewForUserSavingValueOfMoneyOrTime(String.valueOf(savings), R.string.money_time, moneyOrTimeTextView);
moneyOrTimeTextView.setBackground(getResources().getDrawable(R.drawable.custom_button_round));
}
@SideEffect
private void setTargetDays() {
try {
//format string of MAX target txt view
if (preferences.contains(COUNTER)) {
counter = preferences.getInt(COUNTER, 0);
}
if (counter == 0) {
textNonSmoker.setText("Press on the leaf to begin");
} else {
textNonSmoker.setText("Non-smoker since");
}
if (counter>=60) {
userMaxCountForHabit = 90;
editor.putInt(getString(R.string.maxCounter), userMaxCountForHabit);
editor.apply();
} else if (counter >= 30) {
userMaxCountForHabit = 60;
editor.putInt(getString(R.string.maxCounter), userMaxCountForHabit);
editor.apply();
} else {
userMaxCountForHabit = 30;
editor.putInt(getString(R.string.maxCounter), userMaxCountForHabit);
editor.apply();
}
userMaxCountForHabit = preferences.getInt(getString(R.string.maxCounter), -1);
setTxtViewForUserMaxCountDaysOnStringVersion(String.valueOf(userMaxCountForHabit),
R.string.target_string, targetTxtViewId);
if (!preferences.contains(CHALLENGES_STRING)) {
challs = "Tap to start a challenge!";
challengeTextViewSubtitle.setText(challs);
} else {
challs = preferences.getString(CHALLENGES_STRING, challs);
challengeTextViewSubtitle.setText(challs);
}
} catch (NullPointerException e) {
e.printStackTrace();
}
//remaining days -- + " " for space between number of days and text
String calcDaysTarget = (userMaxCountForHabit - counter) + "";
String targetCalcDaysTarget = getString(R.string.remaining_days, calcDaysTarget);
remainingDaysTxt.setText(targetCalcDaysTarget);
}
//running task
@SideEffect
private void runningInBackground() {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
Log.d("targaryen", "this AsyncTask running on: " + Thread.currentThread().getName());
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Log.d("targaryen", "this scheduleAtFixedRate running on: " + Thread.currentThread().getName());
//run till status bar is 100%
runOnUiThread(new Runnable() {
@Override
public void run() {
startTheEngine();
}//run from runonuithread
});//runonuithread
}//run from Timertask
}, 100, 10_000);//Timertask once per 10 SECONDS
}//run from async
});//async
}//runningInBackground
@SideEffect
private void startTheEngine() {
try {
//set text for checkin
setCheckInText();
showEntireProgressForUserCard(userCigaretesProgressTxt, userRankProgressTxt, userHoursProgressTxt);
if (preferences.contains(COUNTER)) {
counter = preferences.getInt(COUNTER, -1);editor.putInt(COUNTER, counter);
editor.apply();
}
setImagesForAchievementCard();
setImprovementProgressLevels();
DAY_OF_CLICK = preferences.getInt(CLICKDAY_SP, 0);
buttonClickedToday = preferences.getBoolean(CLICKED, false);