Skip to content

Commit

Permalink
Add support for fb interstial
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkumar66 committed Apr 4, 2020
1 parent f18d5bc commit 9dc3d9d
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 55 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".PerfTweakerApplication">
android:name=".PerfTweakerApplication"
android:hardwareAccelerated="true">
<!-- <meta-data-->
<!-- android:name="com.google.android.gms.ads.APPLICATION_ID"-->
<!-- android:value="ca-app-pub-5017946957970461~3483969072"/>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;

import com.crashlytics.android.Crashlytics;
import com.facebook.ads.AudienceNetworkAds;

import io.fabric.sdk.android.Fabric;

Expand All @@ -15,6 +16,7 @@ public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
PerfTweakerApplication.context = getApplicationContext();
AudienceNetworkAds.initialize(this);
}

public static Context getAppContext() {
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/java/com/performancetweaker/app/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
Expand All @@ -22,9 +23,11 @@
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.AdListener;
import com.facebook.ads.AdSize;
import com.facebook.ads.AudienceNetworkAds;
import com.facebook.ads.*;
import com.facebook.ads.AdView;
import com.google.android.material.navigation.NavigationView;
import com.performancetweaker.app.R;
import com.performancetweaker.app.ui.fragments.BuildPropEditorFragment;
Expand All @@ -39,14 +42,14 @@
import com.performancetweaker.app.ui.fragments.WakeLocksFragment;
import com.performancetweaker.app.utils.CPUHotplugUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.FANInterstialHelper;
import com.performancetweaker.app.utils.GpuUtils;
import com.stericson.RootTools.RootTools;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

private DrawerLayout mDrawerLayout;
private InterstitialAd mInterstitialAd;

private Toolbar toolbar;
private ActionBarDrawerToggle mDrawerToggle;
Expand All @@ -57,6 +60,7 @@ public class MainActivity extends AppCompatActivity
private GpuUtils gpuUtils;
private AdView adView;
private LinearLayout adContainer;
private String TAG = Constants.App_Tag;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -73,37 +77,33 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();

AudienceNetworkAds.initialize(this);
Log.e("GANDA",Constants.BANNER_AD_PLACEMENT_ID);
adView = new AdView(this, Constants.BANNER_AD_PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);
adContainer.addView(adView);

adView.setAdListener(new AdListener() {
@Override
public void onError(Ad ad, AdError adError) {
// Ad error callback
Toast.makeText(MainActivity.this, "Error: " + adError.getErrorMessage(),
Toast.LENGTH_LONG).show();
Log.e(TAG, "ERROR:BANNER-AD: " + adError.getErrorMessage());
}

@Override
public void onAdLoaded(Ad ad) {
// Ad loaded callback
Toast.makeText(MainActivity.this, "Error: ",
Toast.LENGTH_LONG).show();
Log.e(TAG, "BANNER-AD: loaded successfully");
}

@Override
public void onAdClicked(Ad ad) {
// Ad clicked callback
Log.e(TAG, "BANNER-AD: clicked");
}

@Override
public void onLoggingImpression(Ad ad) {
// Ad impression logged callback
Log.e(TAG, "BANNER-AD: logging impression");
}
});
adView.loadAd();
FANInterstialHelper helper = FANInterstialHelper.getInstance(this);
helper.loadAd();
helper.showAd();

//disable the navigation bar initially
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Expand Down Expand Up @@ -203,6 +203,7 @@ public void run() {
fragment = new CpuHotplugFragment();
actionBar.setTitle(getString(R.string.cpu_hotplug));
break;

}
if (fragment != null) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.CpuFrequencyUtils;
import com.performancetweaker.app.utils.FANInterstialHelper;


public class CpuFrequencyFragment extends PreferenceFragment
Expand All @@ -28,6 +29,7 @@ public class CpuFrequencyFragment extends PreferenceFragment
// Preference preference;
Context context;
ProgressBar progressBar;
FANInterstialHelper fanInterstialHelper;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -62,6 +64,15 @@ public void onResume() {
super.onResume();
updatePreferences();
progressBar.setVisibility(View.GONE);
fanInterstialHelper = FANInterstialHelper.getInstance(context);
fanInterstialHelper.loadAd();
}

@Override
public void onDestroy() {
fanInterstialHelper.destroyAd();
super.onDestroy();

}

public void populatePreferences() {
Expand Down Expand Up @@ -94,6 +105,7 @@ public void updatePreferences() {

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
fanInterstialHelper.showAd();
if (preference.getKey().equals(Constants.PREF_CPU_MIN_FREQ)) {
CpuFrequencyUtils.setMinFrequency(o.toString(), context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public interface Constants {

String APK_NAME = "performancetweaker.apk";

String INTERSTITIAL_AD_PLACEMENT_ID = "YOUR_INTERSTITIAL_AD_PLACEMENT_ID";
String INTERSTITIAL_AD_PLACEMENT_ID = "2399395553684712_2399705310320403";
String BANNER_AD_PLACEMENT_ID = "IMG_16_9_APP_INSTALL#2399395553684712_2399477567009844";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.performancetweaker.app.utils;

import android.content.Context;
import android.util.Log;

import com.facebook.ads.Ad;
import com.facebook.ads.AdError;
import com.facebook.ads.InterstitialAd;
import com.facebook.ads.InterstitialAdListener;

public class FANInterstialHelper {

private static InterstitialAd interstitialAd;
private static String TAG = Constants.App_Tag;
private static FANInterstialHelper interstialHelper;

private FANInterstialHelper(Context context) {
interstitialAd = new InterstitialAd(context, Constants.INTERSTITIAL_AD_PLACEMENT_ID);
interstitialAd.setAdListener(new InterstitialAdListener() {
@Override
public void onInterstitialDisplayed(Ad ad) {
Log.e(TAG, "FAN Interstitial ad displayed.");
}

@Override
public void onInterstitialDismissed(Ad ad) {
Log.e(TAG, "FAN Interstitial ad dismissed.");
interstitialAd.loadAd();
}

@Override
public void onError(Ad ad, AdError adError) {
Log.e(TAG, "FAN Interstitial ad failed to load: " + adError.getErrorMessage());
}

@Override
public void onAdLoaded(Ad ad) {
Log.d(TAG, "FAN: Interstitial ad is loaded and ready to be displayed!");
}

@Override
public void onAdClicked(Ad ad) {
Log.d(TAG, "FAN Interstitial ad clicked!");
}

@Override
public void onLoggingImpression(Ad ad) {
Log.d(TAG, "FAN Interstitial ad impression logged!");
}
});
}

public static FANInterstialHelper getInstance(Context ctx) {
if (interstialHelper == null) {
interstialHelper = new FANInterstialHelper(ctx);
}
return interstialHelper;
}

public void loadAd() {
interstitialAd.loadAd();
}

public void showAd() {
// Check if interstitialAd has been loaded successfully
if(interstitialAd == null || !interstitialAd.isAdLoaded()) {
return;
}
// Check if ad is already expired or invalidated, and do not show ad if that is the case. You will not get paid to show an invalidated ad.
if(interstitialAd.isAdInvalidated()) {
interstitialAd.loadAd();
return;
}
// Show the ad
interstitialAd.show();
}

public void destroyAd() {
if (interstitialAd != null) {
interstitialAd.destroy();
}
}
}
76 changes: 37 additions & 39 deletions app/src/main/res/menu/navigation_drawer_menu.xml
Original file line number Diff line number Diff line change
@@ -1,81 +1,79 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:title="Kernel">
<item android:title="Kernel">

<menu>
<group
android:id="@+id/kernel_tweaks"
android:checkableBehavior="single">
android:id="@+id/kernel_tweaks"
android:checkableBehavior="single">

<item
android:id="@+id/nav_cpu"
android:title="CPU"
android:visible="true"/>
android:id="@+id/nav_cpu"
android:title="CPU"
android:visible="true" />
<item
android:id="@+id/nav_cpu_hotplug"
android:title="CPU Hotplug"
android:visible="false"
/>
android:id="@+id/nav_cpu_hotplug"
android:title="CPU Hotplug"
android:visible="false" />
<item
android:id="@+id/nav_gpu"
android:title="GPU"
android:visible="false"/>
android:id="@+id/nav_gpu"
android:title="GPU"
android:visible="false" />
<item
android:id="@+id/nav_iocontrol"
android:title="I/O Control"
android:visible="true"/>
android:id="@+id/nav_iocontrol"
android:title="I/O Control"
android:visible="true" />
</group>
</menu>
</item>

<item
android:title="Stats">
<item android:title="Stats">

<menu>
<group
android:id="@+id/stats"
android:checkableBehavior="single">
android:id="@+id/stats"
android:checkableBehavior="single">

<item
android:id="@+id/nav_wakelocks"
android:title="Wakelocks"/>
android:id="@+id/nav_wakelocks"
android:title="Wakelocks" />

<item
android:id="@+id/nav_tis"
android:title="Time In State"/>
android:id="@+id/nav_tis"
android:title="Time In State" />

</group>
</menu>
</item>

<item
android:title="Tools">
<item android:title="Tools">

<menu>
<group
android:id="@+id/tools"
android:checkableBehavior="single">
android:id="@+id/tools"
android:checkableBehavior="single">
<item
android:id="@+id/build_prop"
android:title="Build Prop Editor"/>
android:id="@+id/build_prop"
android:title="Build Prop Editor" />
<item
android:id="@+id/vm"
android:title="Virtual Memory"/>
android:id="@+id/vm"
android:title="Virtual Memory" />
</group>
</menu>
</item>
<item
android:title="Misc">
<item android:title="Misc">

<menu>
<group
android:id="@+id/misc"
android:checkableBehavior="single">
android:id="@+id/misc"
android:checkableBehavior="single">

<item
android:id="@+id/nav_settings"
android:title="Settings"/>
android:id="@+id/nav_settings"
android:title="Settings" />
<item
android:id="@+id/remove_ads_1day"
android:title="Remove Ads(Free)" />
</group>
</menu>
</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<string name="cpu_hotplug">CPU Hotplug</string>
<string name="time_in_state">Time In State</string>
<string name="settings">Settings</string>
<string name="remove_ads">Remove Ads(Free)</string>
<string name="vm">Virtual Memory</string>
<string name="build_prop">Build Prop Editor</string>

Expand Down

0 comments on commit 9dc3d9d

Please sign in to comment.