Skip to content

Commit 95706ed

Browse files
committed
ads added
1 parent 61ebb4c commit 95706ed

28 files changed

+346
-50
lines changed

.idea/gradle.xml

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

.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: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/app-release.apk

3.33 MB
Binary file not shown.

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ android {
2020
}
2121

2222
dependencies {
23+
// compile project(':BaseGameUtils')
2324
compile fileTree(dir: 'libs', include: ['*.jar'])
2425
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2526
exclude group: 'com.android.support', module: 'support-annotations'

app/src/main/AndroidManifest.xml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package="com.ayush.bitmath">
44

55
<uses-permission android:name="android.permission.VIBRATE" />
6+
<uses-permission android:name="android.permission.INTERNET"/>
67
<application
78
android:allowBackup="true"
89
android:icon="@mipmap/ic_launcher"
@@ -21,21 +22,32 @@
2122

2223
<activity
2324
android:name=".Activity.GameActivity"
25+
android:screenOrientation="portrait"
2426
android:windowSoftInputMode="stateAlwaysVisible">
2527

2628
</activity>
2729

28-
<activity android:name=".Activity.SplashActivity">
30+
<activity android:name=".Activity.SplashActivity"
31+
android:screenOrientation="portrait">
2932
<intent-filter>
3033
<action android:name="android.intent.action.MAIN" />
3134

3235
<category android:name="android.intent.category.LAUNCHER" />
3336
</intent-filter>
3437
</activity>
35-
<activity android:name=".Activity.HomeActivity"></activity>
38+
<activity android:name=".Activity.HomeActivity"
39+
android:screenOrientation="portrait"></activity>
3640
<activity
3741
android:name=".Activity.ScoreActivity"
38-
android:theme="@style/Theme.AppCompat.Dialog"></activity>
42+
android:label="Score Board"
43+
android:screenOrientation="portrait"
44+
android:theme="@style/NoTitleDialog"></activity>
45+
46+
<!--Include the AdActivity configChanges and theme. -->
47+
<activity
48+
android:name="com.google.android.gms.ads.AdActivity"
49+
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
50+
android:theme="@android:style/Theme.Translucent" />
3951
</application>
4052

4153
</manifest>

app/src/main/java/com/ayush/bitmath/Activity/GameActivity.java

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,29 @@
1818
import com.ayush.bitmath.R;
1919
import com.ayush.bitmath.Utils.Constants;
2020
import com.ayush.bitmath.Utils.Utils;
21+
import com.google.android.gms.ads.AdListener;
2122
import com.google.android.gms.ads.AdRequest;
2223
import com.google.android.gms.ads.AdView;
24+
import com.google.android.gms.ads.InterstitialAd;
25+
import com.google.android.gms.ads.MobileAds;
26+
import com.google.android.gms.ads.NativeExpressAdView;
2327

2428
public class GameActivity extends AppCompatActivity {
25-
29+
InterstitialAd mInterstitialAd;
2630
private TextView textViewTimer, textViewEquation, textViewScore;
2731
private EditText outputEditText;
2832
private Addition addition;
2933
private int score = 0;
3034
boolean isTimerStart = false;
3135
private ProgressBar progressBarTimer;
3236
private AdView mAdView;
37+
private NativeExpressAdView mNativeAd;
3338

3439
@Override
3540
protected void onCreate(Bundle savedInstanceState) {
3641
super.onCreate(savedInstanceState);
3742
setContentView(R.layout.game_activity);
43+
MobileAds.initialize(this, "ca-app-pub-8614462024900398~3850308663");
3844
init();
3945
}
4046

@@ -44,11 +50,62 @@ private void init() {
4450
textViewScore = (TextView) findViewById(R.id.textScore);
4551
outputEditText = (EditText) findViewById(R.id.outputEditText);
4652
progressBarTimer = (ProgressBar) findViewById(R.id.progressBarCircle);
47-
mAdView = (AdView) findViewById(R.id.adView);
48-
loadBannerAds();
53+
mAdView = (AdView) findViewById(R.id.adView);
54+
// mNativeAd = (NativeExpressAdView)findViewById(R.id.adView1);
55+
// mAd= (NativeExpressAdView) findViewById(R.id.adView);
56+
loadBannerAds();
57+
// showAdd();
58+
//showNativeAdd();
4959
progressBarTimer.setMax(Constants.GAME_TIMER);
5060

5161
}
62+
public void showNativeAdd(){
63+
64+
if (Utils.isNetworkAvailable(getApplicationContext())){
65+
AdRequest request = new AdRequest.Builder().addTestDevice(getResources().getString(R.string.test_id_1))
66+
.addTestDevice(getResources().getString(R.string.test_id_2))
67+
.addTestDevice(getResources().getString(R.string.test_id_3)).build();
68+
mNativeAd.loadAd(request);}
69+
else {
70+
mNativeAd.setVisibility(View.GONE);
71+
}
72+
}
73+
public void showAdd()
74+
{
75+
76+
77+
mInterstitialAd = new InterstitialAd(this);
78+
79+
// set the ad unit ID
80+
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
81+
82+
if (Utils.isNetworkAvailable(getApplicationContext())) {
83+
84+
85+
AdRequest adRequest = new AdRequest.Builder()
86+
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
87+
// Check the LogCat to get your test device ID
88+
.addTestDevice(getResources().getString(R.string.test_id_1))
89+
.addTestDevice(getResources().getString(R.string.test_id_2))
90+
.addTestDevice(getResources().getString(R.string.test_id_3))
91+
.build();
92+
mInterstitialAd.loadAd(adRequest);
93+
}
94+
// Load ads into Interstitial Ads
95+
96+
97+
mInterstitialAd.setAdListener(new AdListener() {
98+
public void onAdLoaded() {
99+
showInterstitial();
100+
}
101+
});
102+
}
103+
104+
private void showInterstitial() {
105+
if (mInterstitialAd.isLoaded()) {
106+
mInterstitialAd.show();
107+
}
108+
}
52109

53110
@Override
54111
protected void onResume() {

app/src/main/java/com/ayush/bitmath/Activity/HomeActivity.java

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,104 @@
11
package com.ayush.bitmath.Activity;
22

33
import android.content.Intent;
4+
import android.content.SharedPreferences;
45
import android.graphics.Typeface;
56
import android.os.Bundle;
7+
import android.support.annotation.NonNull;
8+
import android.support.annotation.Nullable;
69
import android.support.v7.app.AppCompatActivity;
10+
import android.util.Log;
711
import android.view.View;
812
import android.view.animation.Animation;
913
import android.view.animation.AnimationUtils;
1014
import android.widget.Button;
1115
import android.widget.LinearLayout;
1216
import android.widget.RelativeLayout;
17+
import android.widget.Toast;
1318

1419
import com.ayush.bitmath.MyBounceInterpolator;
1520
import com.ayush.bitmath.R;
1621
import com.ayush.bitmath.Utils.Constants;
22+
import com.ayush.bitmath.Utils.MyGoogleApiClient_Singleton;
23+
import com.ayush.bitmath.Utils.Utils;
24+
import com.google.android.gms.ads.AdListener;
25+
import com.google.android.gms.ads.AdRequest;
26+
import com.google.android.gms.ads.InterstitialAd;
27+
import com.google.android.gms.common.ConnectionResult;
28+
import com.google.android.gms.common.api.GoogleApiClient;
29+
import com.google.android.gms.games.Games;
1730

18-
public class HomeActivity extends AppCompatActivity {
31+
public class HomeActivity extends AppCompatActivity {
1932

2033
private Animation mAnimation;
34+
InterstitialAd mInterstitialAd;
2135
private RelativeLayout relativeLayoutLogo;
2236
private LinearLayout linearLayoutButton;
2337
private Button buttonPlay, buttonHighScore, buttonShare;
2438

39+
// GoogleApiClient apiClient;
40+
public static GoogleApiClient apiClient;
2541
@Override
2642
protected void onCreate(Bundle savedInstanceState) {
2743
super.onCreate(savedInstanceState);
2844

45+
apiClient = new GoogleApiClient.Builder(this)
46+
.addApi(Games.API)
47+
.addScope(Games.SCOPE_GAMES)
48+
.enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
49+
@Override
50+
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
51+
// Log.e(getApplicationContext(), "Could not connect to Play games services");
52+
// finish();
53+
}
54+
}).build();
55+
// MyGoogleApiClient_Singleton.getInstance(apiClient);
2956
setContentView(R.layout.activity_home);
57+
58+
showAdd();
3059
init();
60+
61+
}
62+
63+
64+
public void showAdd()
65+
{
66+
67+
68+
mInterstitialAd = new InterstitialAd(this);
69+
70+
// set the ad unit ID
71+
mInterstitialAd.setAdUnitId(getString(R.string.interstitial_full_screen));
72+
73+
if (Utils.isNetworkAvailable(getApplicationContext())) {
74+
75+
76+
AdRequest adRequest = new AdRequest.Builder()
77+
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
78+
// Check the LogCat to get your test device ID
79+
.addTestDevice(getResources().getString(R.string.test_id_1))
80+
.addTestDevice(getResources().getString(R.string.test_id_2))
81+
.addTestDevice(getResources().getString(R.string.test_id_3))
82+
.build();
83+
mInterstitialAd.loadAd(adRequest);
84+
}
85+
// Load ads into Interstitial Ads
86+
87+
88+
mInterstitialAd.setAdListener(new AdListener() {
89+
public void onAdLoaded() {
90+
showInterstitial();
91+
}
92+
});
93+
}
94+
95+
private void showInterstitial() {
96+
if (mInterstitialAd.isLoaded()) {
97+
mInterstitialAd.show();
98+
}
3199
}
32100

101+
33102
@Override
34103
protected void onStart() {
35104
super.onStart();
@@ -51,6 +120,7 @@ public void onClick(View v) {
51120
}
52121
});
53122

123+
54124
}
55125

56126
private void init() {
@@ -69,5 +139,37 @@ private void init() {
69139
buttonHighScore.setTypeface(face);
70140
buttonShare.setTypeface(face);
71141

142+
72143
}
144+
public void showLeaderboard(View v) {
145+
SharedPreferences sharedPreferencesScore = getSharedPreferences(Constants.SHARED_PREF_SCORE, 0);
146+
147+
int hScore=Integer.parseInt(String.valueOf((sharedPreferencesScore.getInt(Constants.SHARED_PREF_SCORE_HIGH_SCORE, 0))));
148+
//Toast.makeText(this,""+hScore,Toast.LENGTH_SHORT).show();
149+
// Games.Leaderboards.submitScore(apiClient,
150+
// getString(R.string.leaderboard_my_leaderboard),
151+
// 15);
152+
startActivityForResult(
153+
154+
Games.Leaderboards.getLeaderboardIntent(apiClient,
155+
getString(R.string.leaderboard_my_leaderboard)), 0);
156+
}
157+
public void share(View v) {
158+
// Games.Leaderboards.submitScore(HomeActivity.apiClient,
159+
// getString(R.string.leaderboard_my_leaderboard),
160+
// 18);
161+
Intent intent = new Intent(Intent.ACTION_SEND);
162+
intent.setType("text/plain");
163+
intent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=com.ayush.bitmath");
164+
startActivity(Intent.createChooser(intent, "Share using"));
165+
166+
}
167+
168+
/*
169+
PASTE UNDER SCORE ++ FOR ACHIEVEMENT UNLOCK LIGHTNING FAST
170+
* if(score>20)
171+
{
172+
Games.Achievements.unlock(apiClient,getString(R.string.achievement_lightning_fast));
173+
}
174+
* */
73175
}

0 commit comments

Comments
 (0)