Skip to content

Commit

Permalink
Optimize Interstial Ads
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkumar66 committed Apr 5, 2020
1 parent 9dc3d9d commit 5ee125a
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 55 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package="com.performancetweaker.app"
android:installLocation="internalOnly">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.BATTERY_STATS" />
Expand Down
32 changes: 13 additions & 19 deletions app/src/main/java/com/performancetweaker/app/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
Expand All @@ -39,7 +38,6 @@
import com.performancetweaker.app.ui.fragments.SettingsFragment;
import com.performancetweaker.app.ui.fragments.TimeInStatesFragment;
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.FANInterstialHelper;
Expand All @@ -60,6 +58,7 @@ public class MainActivity extends AppCompatActivity
private GpuUtils gpuUtils;
private AdView adView;
private LinearLayout adContainer;
private FANInterstialHelper fanInterstialHelper;
private String TAG = Constants.App_Tag;

@Override
Expand All @@ -76,7 +75,6 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar(toolbar);
actionBar = getSupportActionBar();

adView = new AdView(this, Constants.BANNER_AD_PLACEMENT_ID, AdSize.BANNER_HEIGHT_50);
adContainer.addView(adView);
adView.setAdListener(new AdListener() {
Expand All @@ -87,23 +85,22 @@ public void onError(Ad ad, AdError adError) {

@Override
public void onAdLoaded(Ad ad) {
Log.e(TAG, "BANNER-AD: loaded successfully");
Log.i(TAG, "BANNER-AD: loaded successfully");
}

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

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

//disable the navigation bar initially
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Expand Down Expand Up @@ -133,6 +130,7 @@ protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
fanInterstialHelper.destroyAd();
super.onDestroy();
}

Expand Down Expand Up @@ -179,10 +177,10 @@ public void run() {
fragment = new IOControlFragment();
actionBar.setTitle(getString(R.string.io));
break;
case R.id.nav_wakelocks:
fragment = new WakeLocksFragment();
actionBar.setTitle(getString(R.string.wakelocks));
break;
// case R.id.nav_wakelocks:
// fragment = new WakeLocksFragment();
// actionBar.setTitle(getString(R.string.wakelocks));
// break;
case R.id.nav_settings:
fragment = new SettingsFragment();
actionBar.setTitle(getString(R.string.settings));
Expand All @@ -203,7 +201,6 @@ public void run() {
fragment = new CpuHotplugFragment();
actionBar.setTitle(getString(R.string.cpu_hotplug));
break;

}
if (fragment != null) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
Expand Down Expand Up @@ -256,22 +253,19 @@ protected void onPostExecute(Void aVoid) {
if (hasRoot && hasBusyBox) {
populateGui();
} else {

progressBar.setVisibility(View.GONE);

appCompatibilityMessage.setVisibility(View.VISIBLE);
appCompatibilityMessage
.setText(!hasRoot ? "No root access found" : "No Busybox found");

if (hasRoot) {
//TODO redirect to playstore for installing busybox
try {
startActivity(
new Intent(Intent.ACTION_VIEW, Uri
.parse("market://details?id=stericson.busybox")));
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=stericson.busybox")));
} catch (ActivityNotFoundException ignored) {
}
}
fanInterstialHelper.showAd();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

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

import java.util.LinkedHashMap;

Expand All @@ -40,6 +41,7 @@ public class BuildPropEditorFragment extends PreferenceFragment
Context context;

ProgressBar progressBar;
FANInterstialHelper fanInterstialHelper;

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

context = getActivity();
fanInterstialHelper = FANInterstialHelper.getInstance(getActivity());
}

@Override
Expand All @@ -66,6 +69,7 @@ public void onResume() {

@Override
public boolean onPreferenceChange(Preference preference, Object o) {
fanInterstialHelper.showAd();
BuildPropUtils.overwrite(preference.getKey(), preference.getSummary().toString(),
preference.getKey(), o.toString());
preference.setSummary(o.toString());
Expand Down Expand Up @@ -132,7 +136,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void editBuildPropDialog() {

Activity activity = getActivity();
final View editDialog =
LayoutInflater.from(getActivity()).inflate(R.layout.dialog_build_prop, null, false);
Expand All @@ -149,15 +152,15 @@ public void onClick(DialogInterface dialog, int which) {
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
fanInterstialHelper.showAd();
if (etValue.getText() != null && etName.getText() != null) {
BuildPropUtils.addKey(etName.getText().toString().trim(),
etValue.getText().toString().trim());
} else {
return;
}
}
})
.show();
}).show();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,16 @@ public void onCreate(Bundle savedInstanceState) {
CpuMaxFreqPreference.setOnPreferenceChangeListener(this);
CpuMinFreqPreference.setOnPreferenceChangeListener(this);
GovernorPreference.setOnPreferenceChangeListener(this);

fanInterstialHelper = FANInterstialHelper.getInstance(getActivity());
fanInterstialHelper.loadAd();
}

@Override
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.CPUHotplugUtils;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.FANInterstialHelper;

public class CpuHotplugFragment extends PreferenceFragment
implements Preference.OnPreferenceChangeListener {

Context context;
SwitchPreference switchPreference;
FANInterstialHelper fanInterstialHelper;

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

@Override
Expand All @@ -44,6 +47,7 @@ public void onResume() {

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
fanInterstialHelper.showAd();
CPUHotplugUtils.activateMpdecision(Boolean.parseBoolean(newValue.toString()));
switchPreference.setChecked(CPUHotplugUtils.isMpdecisionActive());
return Boolean.parseBoolean(newValue.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

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

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

fanInterstialHelper = FANInterstialHelper.getInstance(getActivity());
}

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

@Override
public boolean onPreferenceChange(Preference preference, Object value) {
fanInterstialHelper.showAd();
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 @@ -11,6 +11,7 @@

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

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

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

IOScheduler.setOnPreferenceChangeListener(this);
ReadAheadCache.setOnPreferenceChangeListener(this);
fanInterstialHelper = FANInterstialHelper.getInstance(getActivity());
}

private void populatePreferences() {
Expand Down Expand Up @@ -91,6 +94,7 @@ public void updateData() {
}

public void updatePreferences() {
fanInterstialHelper.showAd();
IOScheduler.setSummary(currentScheduler);
ReadAheadCache.setSummary(currentReadAhead);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.performancetweaker.app.R;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.FANInterstialHelper;
import com.performancetweaker.app.utils.GpuUtils;
import com.performancetweaker.app.utils.SystemAppUtilities;

Expand All @@ -22,6 +23,7 @@ public class SettingsFragment extends PreferenceFragment {
MultiSelectListPreference mMultiSelectListPreference;
Preference uninstallSystemAppButton;
GpuUtils gpuUtils;
FANInterstialHelper fanInterstialHelper;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -42,6 +44,7 @@ public void onCreate(Bundle paramBundle) {
uninstallSystemAppButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
fanInterstialHelper.showAd();
Boolean status = SystemAppUtilities.uninstallAsSystemApp(Constants.APK_NAME);
if(status) {
if(!SystemAppUtilities.isSystemApp(Constants.APK_NAME)) {
Expand Down Expand Up @@ -70,9 +73,17 @@ public boolean onPreferenceClick(Preference preference) {
}
mMultiSelectListPreference.setEntries(charSequences);
mMultiSelectListPreference.setEntryValues(charSequences);
mMultiSelectListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
fanInterstialHelper.showAd();
return true;
}
});

if(!SystemAppUtilities.isSystemApp(Constants.APK_NAME)) {
preferenceCategory.removePreference(uninstallSystemAppButton);
}
fanInterstialHelper = FANInterstialHelper.getInstance(getActivity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.performancetweaker.app.R;
import com.performancetweaker.app.ui.adapters.TimeInStatesListAdapter;
import com.performancetweaker.app.utils.Constants;
import com.performancetweaker.app.utils.FANInterstialHelper;
import com.performancetweaker.app.utils.SysUtils;

public class TimeInStatesFragment extends Fragment {
Expand All @@ -31,6 +32,7 @@ public class TimeInStatesFragment extends Fragment {
Context context;
CardView cardView;
Integer adClickThreshold = 0;
FANInterstialHelper fanInterstialHelper;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -64,6 +66,7 @@ public void onActivityCreated(Bundle savedInstanceState) {

totalTimeInState.setText(SysUtils.secToString(timeInStateAdapter.totaltime / 100));
timeInStateAdapter.refresh();
fanInterstialHelper = FANInterstialHelper.getInstance(getActivity());
}

@Override
Expand Down Expand Up @@ -94,6 +97,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
default:
break;
}
if (adClickThreshold % 2 == 0) {
fanInterstialHelper.showAd();
}
return super.onOptionsItemSelected(item);
}
}
Loading

0 comments on commit 5ee125a

Please sign in to comment.