Skip to content

Commit

Permalink
Add support for fb ads
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkumar66 committed Apr 4, 2020
1 parent 4bda2e9 commit bf3465c
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 150 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {
implementation 'com.github.lzyzsd:circleprogress:1.2.1'
implementation 'org.codehaus.jackson:jackson-core-asl:1.9.13'
implementation 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
implementation 'com.google.android.gms:play-services-ads-lite:19.0.1'
implementation 'com.facebook.android:audience-network-sdk:5.8.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
transitive = true;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".PerfTweakerApplication">
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-5017946957970461~3483969072"/>
<!-- <meta-data-->
<!-- android:name="com.google.android.gms.ads.APPLICATION_ID"-->
<!-- android:value="ca-app-pub-5017946957970461~3483969072"/>-->

<activity
android:name="com.performancetweaker.app.ui.MainActivity"
Expand Down
40 changes: 27 additions & 13 deletions app/src/main/java/com/performancetweaker/app/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
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;
import android.widget.ProgressBar;
import android.widget.TextView;

Expand All @@ -20,12 +22,9 @@
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.facebook.ads.AdSize;
import com.facebook.ads.AudienceNetworkAds;
import com.facebook.ads.*;
import com.google.android.material.navigation.NavigationView;
import com.performancetweaker.app.R;
import com.performancetweaker.app.ui.fragments.BuildPropEditorFragment;
Expand All @@ -39,6 +38,7 @@
import com.performancetweaker.app.ui.fragments.VirtualMemoryFragment;
import com.performancetweaker.app.ui.fragments.WakeLocksFragment;
import com.performancetweaker.app.utils.CPUHotplugUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.GpuUtils;
import com.stericson.RootTools.RootTools;

Expand All @@ -55,6 +55,8 @@ public class MainActivity extends AppCompatActivity
private TextView appCompatibilityMessage;
private ProgressBar progressBar;
private GpuUtils gpuUtils;
private AdView adView;
private LinearLayout adContainer;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -66,10 +68,19 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar = findViewById(R.id.toolbar);
appCompatibilityMessage = findViewById(R.id.app_compatibility_status);
progressBar = findViewById(R.id.loading_main);
adContainer = findViewById(R.id.ad_container);

setSupportActionBar(toolbar);
actionBar = getSupportActionBar();

Log.e("CHUTIYA",Constants.BANNER_AD_PLACEMENT_ID+"CHITIYA");

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.loadAd();

//disable the navigation bar initially
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

Expand All @@ -89,16 +100,19 @@ public void onDrawerClosed(View drawerView) {
mDrawerToggle.syncState();
mDrawerLayout.setDrawerListener(mDrawerToggle);
navigationView.setNavigationItemSelectedListener(this);
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);


new Task().execute();
}

@Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}

public void populateGui() {

//enable navigation drawer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import androidx.core.view.MenuItemCompat;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.BuildPropUtils;

import java.util.LinkedHashMap;
Expand All @@ -41,7 +40,6 @@ public class BuildPropEditorFragment extends PreferenceFragment
Context context;

ProgressBar progressBar;
AdUtils adUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -58,8 +56,6 @@ public void onCreate(Bundle savedInstanceState) {
progressBar.setVisibility(View.VISIBLE);

context = getActivity();
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();
}

@Override
Expand All @@ -73,7 +69,6 @@ public boolean onPreferenceChange(Preference preference, Object o) {
BuildPropUtils.overwrite(preference.getKey(), preference.getSummary().toString(),
preference.getKey(), o.toString());
preference.setSummary(o.toString());
adUtils.showInterstialAd();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.widget.ProgressBar;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.CpuFrequencyUtils;

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -45,8 +43,6 @@ public void onCreate(Bundle savedInstanceState) {
setHasOptionsMenu(true);
addPreferencesFromResource(R.xml.cpu_freq_preference);
context = getActivity().getBaseContext();
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();

CpuMaxFreqPreference = (ListPreference) findPreference(Constants.PREF_CPU_MAX_FREQ);
CpuMinFreqPreference = (ListPreference) findPreference(Constants.PREF_CPU_MIN_FREQ);
Expand Down Expand Up @@ -109,7 +105,6 @@ public boolean onPreferenceChange(Preference preference, Object o) {
}
updateData();
updatePreferences();
adUtils.showInterstialAd();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.ViewGroup;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.CPUHotplugUtils;
import com.performancetweaker.app.utils.Constants;

Expand All @@ -19,7 +18,6 @@ public class CpuHotplugFragment extends PreferenceFragment

Context context;
SwitchPreference switchPreference;
AdUtils adUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -34,8 +32,6 @@ public void onActivityCreated(Bundle savedInstanceState) {
addPreferencesFromResource(R.xml.cpu_hotplug_preferences);
switchPreference = (SwitchPreference) findPreference(Constants.PREF_HOTPLUG);
context = getActivity().getBaseContext();
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();
}

@Override
Expand All @@ -50,7 +46,6 @@ public void onResume() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
CPUHotplugUtils.activateMpdecision(Boolean.parseBoolean(newValue.toString()));
switchPreference.setChecked(CPUHotplugUtils.isMpdecisionActive());
adUtils.showInterstialAd();
return Boolean.parseBoolean(newValue.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.CpuFrequencyUtils;
import com.performancetweaker.app.utils.GovernorProperty;

Expand All @@ -29,7 +28,6 @@ public class GovernorTuningFragment extends PreferenceFragment
Context context;
View view;
SwipeRefreshLayout swipeRefreshLayout;
AdUtils adUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -59,16 +57,16 @@ public void run() {
new GetGovernorPropertiesTask().execute();
}
}, 500);
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();
// adUtils = AdUtils.getInstance(context);
// adUtils.loadInterstialAd();
}

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
CpuFrequencyUtils.setGovernorProperty(new GovernorProperty(preference.getKey(), o.toString()),
getActivity());
preference.setSummary(o.toString());
adUtils.showInterstialAd();
// adUtils.showInterstialAd();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.ViewGroup;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.GpuUtils;

Expand All @@ -28,7 +27,6 @@ public class GpuControlFragment extends PreferenceFragment
String minFrequency;
String currentGovernor;
GpuUtils gpuUtils;
AdUtils adUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -56,8 +54,6 @@ public void onCreate(Bundle savedInstanceState) {
maxGpuFrequencyPreference.setOnPreferenceChangeListener(this);
minGpuFrequencyPreference.setOnPreferenceChangeListener(this);
availableGpuGovernorPreference.setOnPreferenceChangeListener(this);
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();
}

@Override
Expand Down Expand Up @@ -107,7 +103,6 @@ public void updatePreferences() {

@Override
public boolean onPreferenceChange(Preference preference, Object value) {
adUtils.showInterstialAd();
if (preference.getKey().equals(Constants.PREF_GPU_MAX)) {
gpuUtils.setMaxGpuFrequency(value.toString(), getActivity().getBaseContext());
} else if (preference.getKey().equals(Constants.PREF_GPU_MIN)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.view.ViewGroup;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.IOUtils;

Expand All @@ -24,7 +23,6 @@ public class IOControlFragment extends PreferenceFragment
ListPreference IOScheduler;
ListPreference ReadAheadCache;
Context context;
AdUtils adUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -46,8 +44,6 @@ public void onActivityCreated(Bundle savedInstanceState) {

IOScheduler.setOnPreferenceChangeListener(this);
ReadAheadCache.setOnPreferenceChangeListener(this);
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();
}

private void populatePreferences() {
Expand Down Expand Up @@ -84,7 +80,6 @@ public boolean onPreferenceChange(Preference preference, Object o) {

updateData();
updatePreferences();
adUtils.showInterstialAd();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.widget.Toast;

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.GpuUtils;
import com.performancetweaker.app.utils.SystemAppUtilities;
Expand All @@ -23,7 +22,6 @@ public class SettingsFragment extends PreferenceFragment {
MultiSelectListPreference mMultiSelectListPreference;
Preference uninstallSystemAppButton;
GpuUtils gpuUtils;
AdUtils adUtils;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -53,7 +51,6 @@ public boolean onPreferenceClick(Preference preference) {
}else {
Toast.makeText(getActivity(),"Unknown error occurred while uninstalling app",Toast.LENGTH_SHORT);
}
adUtils.showInterstialAd();
return true;
}
});
Expand All @@ -77,7 +74,5 @@ public boolean onPreferenceClick(Preference preference) {
if(!SystemAppUtilities.isSystemApp(Constants.APK_NAME)) {
preferenceCategory.removePreference(uninstallSystemAppButton);
}
adUtils = AdUtils.getInstance(getActivity());
adUtils.loadInterstialAd();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.performancetweaker.app.R;
import com.performancetweaker.app.ui.adapters.TimeInStatesListAdapter;
import com.performancetweaker.app.utils.AdUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.SysUtils;

Expand All @@ -31,7 +30,6 @@ public class TimeInStatesFragment extends Fragment {
SharedPreferences prefs;
Context context;
CardView cardView;
AdUtils adUtils;
Integer adClickThreshold = 0;

@Override
Expand Down Expand Up @@ -66,8 +64,6 @@ public void onActivityCreated(Bundle savedInstanceState) {

totalTimeInState.setText(SysUtils.secToString(timeInStateAdapter.totaltime / 100));
timeInStateAdapter.refresh();
adUtils = AdUtils.getInstance(context);
adUtils.loadInterstialAd();
}

@Override
Expand All @@ -78,9 +74,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(adClickThreshold % 2 == 0) {
adUtils.showInterstialAd();
}
adClickThreshold++;
switch (item.getItemId()) {
case R.id.refresh:
Expand Down
Loading

0 comments on commit bf3465c

Please sign in to comment.