Skip to content

Commit 61ebb4c

Browse files
committed
code cleaned
1 parent 0cb223f commit 61ebb4c

27 files changed

+525
-467
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
compile 'com.google.firebase:firebase-database:10.0.1'
3333
compile 'com.google.firebase:firebase-storage:10.0.1'
3434
compile 'com.google.firebase:firebase-crash:10.0.1'
35+
compile 'com.google.firebase:firebase-config:10.0.1'
3536
compile 'com.google.android.gms:play-services-ads:10.0.1'
3637
testCompile 'junit:junit:4.12'
3738
}

app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020

2121

2222
<activity
23-
android:name=".MainActivity"
23+
android:name=".Activity.GameActivity"
2424
android:windowSoftInputMode="stateAlwaysVisible">
2525

2626
</activity>
2727

28-
<activity android:name=".SplashActivity">
28+
<activity android:name=".Activity.SplashActivity">
2929
<intent-filter>
3030
<action android:name="android.intent.action.MAIN" />
3131

3232
<category android:name="android.intent.category.LAUNCHER" />
3333
</intent-filter>
3434
</activity>
35-
<activity android:name=".HomeActivity"></activity>
35+
<activity android:name=".Activity.HomeActivity"></activity>
3636
<activity
37-
android:name=".ScoreActivity"
37+
android:name=".Activity.ScoreActivity"
3838
android:theme="@style/Theme.AppCompat.Dialog"></activity>
3939
</application>
4040

app/src/main/java/com/ayush/bitmath/MainActivity.java renamed to app/src/main/java/com/ayush/bitmath/Activity/GameActivity.java

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ayush.bitmath;
1+
package com.ayush.bitmath.Activity;
22

33
import android.content.Context;
44
import android.content.Intent;
@@ -8,23 +8,27 @@
88
import android.support.v7.app.AppCompatActivity;
99
import android.text.Editable;
1010
import android.text.TextWatcher;
11+
import android.view.View;
1112
import android.view.inputmethod.InputMethodManager;
1213
import android.widget.EditText;
1314
import android.widget.ProgressBar;
1415
import android.widget.TextView;
1516

1617
import com.ayush.bitmath.Logical.Addition;
18+
import com.ayush.bitmath.R;
19+
import com.ayush.bitmath.Utils.Constants;
20+
import com.ayush.bitmath.Utils.Utils;
1721
import com.google.android.gms.ads.AdRequest;
1822
import com.google.android.gms.ads.AdView;
1923

20-
public class MainActivity extends AppCompatActivity {
24+
public class GameActivity extends AppCompatActivity {
2125

2226
private TextView textViewTimer, textViewEquation, textViewScore;
2327
private EditText outputEditText;
24-
Addition addition;
25-
int score = 0;
28+
private Addition addition;
29+
private int score = 0;
2630
boolean isTimerStart = false;
27-
ProgressBar progressBarTimer;
31+
private ProgressBar progressBarTimer;
2832
private AdView mAdView;
2933

3034
@Override
@@ -42,45 +46,44 @@ private void init() {
4246
progressBarTimer = (ProgressBar) findViewById(R.id.progressBarCircle);
4347
mAdView = (AdView) findViewById(R.id.adView);
4448
loadBannerAds();
45-
progressBarTimer.setMax(30);
49+
progressBarTimer.setMax(Constants.GAME_TIMER);
4650

4751
}
4852

4953
@Override
5054
protected void onResume() {
5155
super.onResume();
5256
isTimerStart = false;
53-
textViewTimer.setText("Timer");
57+
textViewTimer.setText(Constants.GAME_TIMER + "");
5458
score = 0;
5559
textViewScore.setText(score + "");
5660
outputEditText.setText("");
5761
addition = new Addition();
5862
addition.innerLoop();
59-
progressBarTimer.setProgress(30);
63+
progressBarTimer.setProgress(Constants.GAME_TIMER);
6064
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
6165
inputMethodManager.toggleSoftInputFromWindow(outputEditText.getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
6266
outputEditText.requestFocus();
6367

64-
final CountDownTimer timer = new CountDownTimer(30000, 1000) {
68+
final CountDownTimer timer = new CountDownTimer(Constants.GAME_TIMER * 1000, 1000) {
6569

6670
public void onTick(long millisUntilFinished) {
6771
textViewTimer.setText(millisUntilFinished / 1000 + "");
6872
progressBarTimer.setProgress((int) (millisUntilFinished / 1000));
6973
}
7074

7175
public void onFinish() {
72-
textViewTimer.setText("done");
76+
textViewTimer.setText(0 + "");
7377
progressBarTimer.setProgress(0);
74-
Intent intent = new Intent(MainActivity.this, ScoreActivity.class);
75-
intent.putExtra("currentScore", score);
78+
Intent intent = new Intent(GameActivity.this, ScoreActivity.class);
79+
intent.putExtra(Constants.INTENT_CURRENT_SCORE, score);
7680
startActivity(intent);
7781

7882
}
7983
};
8084

8185

8286
textViewEquation.setText(addition.getEquation());
83-
// ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
8487
outputEditText.addTextChangedListener(new TextWatcher() {
8588

8689
public void afterTextChanged(Editable s) {
@@ -90,12 +93,14 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
9093
}
9194

9295
public void onTextChanged(CharSequence s, int start, int before, int count) {
96+
9397
if (!(s == null || (s.toString()).equals(""))) {
98+
9499
int editTextOutput = Integer.parseInt(s.toString());
95100
if (editTextOutput == addition.getOutput()) {
96101
score++;
97102
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
98-
v.vibrate(40);
103+
v.vibrate(Constants.VIBRATOR_DURATION);
99104
textViewScore.setText(score + "");
100105
addition.innerLoop();
101106
textViewEquation.setText(addition.getEquation());
@@ -111,25 +116,17 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
111116
}
112117

113118

114-
@Override
115-
protected void onPause() {
116-
super.onPause();
117-
// Toast.makeText(getApplicationContext(), "Pause", Toast.LENGTH_LONG).show();
118-
}
119-
120-
@Override
121-
protected void onStop() {
122-
super.onStop();
123-
// Toast.makeText(getApplicationContext(), "Stop", Toast.LENGTH_LONG).show();
124-
}
125-
126119
private void loadBannerAds() {
127-
AdRequest adRequest1 = new AdRequest.Builder()
128-
.addTestDevice(getResources().getString(R.string.test_id_1))
129-
.addTestDevice(getResources().getString(R.string.test_id_2))
130-
.addTestDevice(getResources().getString(R.string.test_id_3))
131-
.build();
132-
mAdView.loadAd(adRequest1);
120+
if (Utils.isNetworkAvailable(getApplicationContext())) {
121+
AdRequest adRequest1 = new AdRequest.Builder()
122+
.addTestDevice(getResources().getString(R.string.test_id_1))
123+
.addTestDevice(getResources().getString(R.string.test_id_2))
124+
.addTestDevice(getResources().getString(R.string.test_id_3))
125+
.build();
126+
mAdView.loadAd(adRequest1);
127+
} else {
128+
mAdView.setVisibility(View.GONE);
129+
}
133130
}
134131

135132
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.ayush.bitmath.Activity;
2+
3+
import android.content.Intent;
4+
import android.graphics.Typeface;
5+
import android.os.Bundle;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
import android.view.animation.Animation;
9+
import android.view.animation.AnimationUtils;
10+
import android.widget.Button;
11+
import android.widget.LinearLayout;
12+
import android.widget.RelativeLayout;
13+
14+
import com.ayush.bitmath.MyBounceInterpolator;
15+
import com.ayush.bitmath.R;
16+
import com.ayush.bitmath.Utils.Constants;
17+
18+
public class HomeActivity extends AppCompatActivity {
19+
20+
private Animation mAnimation;
21+
private RelativeLayout relativeLayoutLogo;
22+
private LinearLayout linearLayoutButton;
23+
private Button buttonPlay, buttonHighScore, buttonShare;
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
29+
setContentView(R.layout.activity_home);
30+
init();
31+
}
32+
33+
@Override
34+
protected void onStart() {
35+
super.onStart();
36+
MyBounceInterpolator interpolator = new MyBounceInterpolator(0.1, 20);
37+
38+
Animation myAnim = AnimationUtils.loadAnimation(this, R.anim.tansition);
39+
mAnimation = AnimationUtils.loadAnimation(this, R.anim.transition2);
40+
myAnim.setFillAfter(true);
41+
mAnimation.setFillAfter(true);
42+
mAnimation.setInterpolator(interpolator);
43+
linearLayoutButton.setVisibility(View.VISIBLE);
44+
linearLayoutButton.setAnimation(mAnimation);
45+
relativeLayoutLogo.setAnimation(myAnim);
46+
buttonPlay.setOnClickListener(new View.OnClickListener() {
47+
@Override
48+
public void onClick(View v) {
49+
Intent i = new Intent(HomeActivity.this, GameActivity.class);
50+
startActivity(i);
51+
}
52+
});
53+
54+
}
55+
56+
private void init() {
57+
buttonPlay = (Button) findViewById(R.id.buttonPlay);
58+
buttonHighScore = (Button) findViewById(R.id.buttonHighScore);
59+
buttonShare = (Button) findViewById(R.id.buttonShare);
60+
findViewById(R.id.buttonPlay).getBackground().setLevel(0);
61+
findViewById(R.id.buttonHighScore).getBackground().setLevel(1);
62+
findViewById(R.id.buttonShare).getBackground().setLevel(2);
63+
64+
linearLayoutButton = (LinearLayout) findViewById(R.id.linearLayoutButton);
65+
relativeLayoutLogo = (RelativeLayout) findViewById(R.id.relativeLayoutLogo);
66+
67+
Typeface face = Typeface.createFromAsset(getAssets(), Constants.TYPEFACE_VTKS_CHALK);
68+
buttonPlay.setTypeface(face);
69+
buttonHighScore.setTypeface(face);
70+
buttonShare.setTypeface(face);
71+
72+
}
73+
}

app/src/main/java/com/ayush/bitmath/ScoreActivity.java renamed to app/src/main/java/com/ayush/bitmath/Activity/ScoreActivity.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
package com.ayush.bitmath;
1+
package com.ayush.bitmath.Activity;
22

33
import android.content.Intent;
44
import android.content.SharedPreferences;
55
import android.os.Bundle;
6-
import android.support.annotation.NonNull;
76
import android.support.v7.app.AppCompatActivity;
87
import android.view.View;
98
import android.widget.Button;
109
import android.widget.ImageView;
1110
import android.widget.LinearLayout;
12-
import android.widget.TextView;
1311

14-
import com.ayush.bitmath.Utils.LogWrapper;
15-
import com.google.android.gms.common.ConnectionResult;
12+
import com.ayush.bitmath.R;
13+
import com.ayush.bitmath.Utils.Constants;
1614
import com.google.android.gms.common.api.GoogleApiClient;
1715
import com.google.android.gms.games.Games;
1816

@@ -28,8 +26,8 @@ public class ScoreActivity extends AppCompatActivity {
2826
protected void onCreate(Bundle savedInstanceState) {
2927
super.onCreate(savedInstanceState);
3028
setContentView(R.layout.score_activity);
31-
Bundle b = getIntent().getExtras();
32-
currentScore = b.getInt("currentScore");
29+
Bundle bundle = getIntent().getExtras();
30+
currentScore = bundle.getInt(Constants.INTENT_CURRENT_SCORE);
3331
init();
3432

3533
}
@@ -39,7 +37,7 @@ private void init() {
3937
textViewHighScore = (Button) findViewById(R.id.highScoreText);
4038
buttonReplay = (ImageView) findViewById(R.id.buttonReplay);
4139
buttonStandings = (ImageView) findViewById(R.id.buttonStandings);
42-
option=(LinearLayout)findViewById(R.id.option);
40+
option = (LinearLayout) findViewById(R.id.option);
4341
findViewById(R.id.scoreText).getBackground().setLevel(0);
4442
findViewById(R.id.highScoreText).getBackground().setLevel(1);
4543
findViewById(R.id.option).getBackground().setLevel(2);
@@ -57,11 +55,11 @@ private void init() {
5755
// .build();
5856

5957
textViewScore.setText(currentScore + "");
60-
SharedPreferences sharedPreferencesScore = getSharedPreferences("Score", 0);
61-
int highScore = (sharedPreferencesScore.getInt("HighScore", 0));
58+
SharedPreferences sharedPreferencesScore = getSharedPreferences(Constants.SHARED_PREF_SCORE, 0);
59+
int highScore = (sharedPreferencesScore.getInt(Constants.SHARED_PREF_SCORE_HIGH_SCORE, 0));
6260
if (highScore < currentScore) {
6361
SharedPreferences.Editor editor = sharedPreferencesScore.edit();
64-
editor.putInt("HighScore", currentScore);
62+
editor.putInt(Constants.SHARED_PREF_SCORE_HIGH_SCORE, currentScore);
6563
editor.apply();
6664
textViewHighScore.setText(currentScore + "");
6765
} else {
@@ -85,9 +83,9 @@ public void onClick(View v) {
8583
/* startActivityForResult(
8684
Games.Leaderboards.getLeaderboardIntent(apiClient,
8785
getString(R.string.leaderboard_bit_math_global_rank)), 0);*/
88-
Intent i=new Intent(ScoreActivity.this,HomeActivity.class);
86+
Intent i = new Intent(ScoreActivity.this, HomeActivity.class);
8987
startActivity(i);
90-
overridePendingTransition(R.anim.fade,R.anim.fadeout);
88+
overridePendingTransition(R.anim.fade, R.anim.fadeout);
9189

9290
}
9391
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.ayush.bitmath.Activity;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.animation.Animation;
7+
import android.view.animation.AnimationUtils;
8+
import android.widget.ImageView;
9+
10+
import com.ayush.bitmath.R;
11+
import com.ayush.bitmath.Utils.Constants;
12+
import com.ayush.bitmath.Utils.LogWrapper;
13+
14+
public class SplashActivity extends AppCompatActivity {
15+
private ImageView imageViewTitle;
16+
17+
@Override
18+
protected void onCreate(Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
setContentView(R.layout.activity_splash);
21+
init();
22+
}
23+
24+
private void init() {
25+
imageViewTitle = (ImageView) findViewById(R.id.imageViewTitle);
26+
}
27+
28+
@Override
29+
protected void onStart() {
30+
super.onStart();
31+
Thread timer = new Thread() {
32+
public void run() {
33+
try {
34+
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade1);
35+
imageViewTitle.startAnimation(animation);
36+
sleep(Constants.SPLASH_ACTIVITY_TIMEOUT);
37+
} catch (InterruptedException e) {
38+
LogWrapper.printStackTrace(getApplicationContext(), e);
39+
} finally {
40+
41+
Intent i = new Intent(SplashActivity.this, HomeActivity.class);
42+
startActivity(i);
43+
overridePendingTransition(R.anim.fade, R.anim.fadeout);
44+
45+
}
46+
}
47+
};
48+
timer.start();
49+
}
50+
51+
@Override
52+
protected void onPause() {
53+
super.onPause();
54+
finish();
55+
}
56+
}

0 commit comments

Comments
 (0)