Skip to content
This repository was archived by the owner on Oct 5, 2019. It is now read-only.

Commit 606fc1d

Browse files
committed
Switch to banner ads
1 parent a343760 commit 606fc1d

12 files changed

Lines changed: 78 additions & 133 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies {
4848
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
4949
exclude group: 'com.android.support', module: 'support-annotations'
5050
})
51-
implementation 'com.google.firebase:firebase-ads:11.8.0'
51+
implementation 'com.google.android.gms:play-services-ads:11.8.0'
5252
implementation 'com.google.firebase:firebase-core:11.8.0'
5353
implementation 'com.google.android.gms:play-services-auth:11.8.0'
5454
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {

app/src/main/java/com/grarak/kerneladiutor/activities/NavigationActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
import com.grarak.kerneladiutor.utils.root.RootUtils;
103103
import com.grarak.kerneladiutor.utils.tools.Backup;
104104
import com.grarak.kerneladiutor.utils.tools.SupportedDownloads;
105-
import com.grarak.kerneladiutor.views.AdNativeExpress;
105+
import com.grarak.kerneladiutor.views.AdLayout;
106106

107107
import java.lang.ref.WeakReference;
108108
import java.util.ArrayList;
@@ -323,7 +323,7 @@ private void init(Bundle savedInstanceState) {
323323
mAdsFetcher = new WebpageReader(this, new WebpageReader.WebpageListener() {
324324
@Override
325325
public void onSuccess(String url, String raw, CharSequence html) {
326-
AdNativeExpress.GHAds ghAds = new AdNativeExpress.GHAds(raw);
326+
AdLayout.GHAds ghAds = new AdLayout.GHAds(raw);
327327
if (ghAds.readable()) {
328328
ghAds.cache(NavigationActivity.this);
329329
Fragment fragment = getFragment(mSelection);
@@ -337,7 +337,7 @@ public void onSuccess(String url, String raw, CharSequence html) {
337337
public void onFailure(String url) {
338338
}
339339
});
340-
mAdsFetcher.get(AdNativeExpress.ADS_FETCH);
340+
mAdsFetcher.get(AdLayout.ADS_FETCH);
341341
}
342342
}
343343

app/src/main/java/com/grarak/kerneladiutor/fragments/other/ContributorsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ protected void addItems(List<RecyclerViewItem> items) {
6464
protected void postInit() {
6565
super.postInit();
6666

67-
showProgress();
6867
if (mWebpageReader == null) {
68+
showProgress();
6969
mWebpageReader = new WebpageReader(getActivity(), new WebpageReader.WebpageListener() {
7070
@Override
7171
public void onSuccess(String url, String raw, CharSequence html) {

app/src/main/java/com/grarak/kerneladiutor/utils/Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public static String upperCaseEachWord(String text) {
9191
for (int i = 0; i < chars.length; i++) {
9292
if (i == 0) {
9393
chars[i] = Character.toUpperCase(chars[0]);
94-
} else if (Character.isWhitespace(chars[i])) {
95-
chars[i] = Character.toUpperCase(chars[i]);
94+
} else if (Character.isWhitespace(chars[i]) && i != chars.length - 1) {
95+
chars[i + 1] = Character.toUpperCase(chars[i + 1]);
9696
}
9797
}
9898

app/src/main/java/com/grarak/kerneladiutor/utils/kernel/misc/Wakelocks.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ public String getTitle(Context context) {
6969
return context.getString(mTitle);
7070
}
7171

72-
String[] paths = mPath.split("/");
73-
return Utils.upperCaseEachWord(paths[paths.length - 1].replace("enable_", "")
74-
.replace("_ws", "").replace("_", " "));
72+
return Utils.upperCaseEachWord(mPath.substring(mPath.lastIndexOf('/') + 1)
73+
.replace("enable_", "")
74+
.replace("_ws", "")
75+
.replace("_", " "));
7576
}
7677

7778
public void enable(boolean enable, Context context) {

app/src/main/java/com/grarak/kerneladiutor/views/AdNativeExpress.java renamed to app/src/main/java/com/grarak/kerneladiutor/views/AdLayout.java

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import android.util.AttributeSet;
3131
import android.view.LayoutInflater;
3232
import android.view.View;
33-
import android.view.ViewGroup;
3433
import android.widget.FrameLayout;
3534
import android.widget.LinearLayout;
3635

@@ -40,7 +39,7 @@
4039
import com.google.android.gms.ads.AdListener;
4140
import com.google.android.gms.ads.AdRequest;
4241
import com.google.android.gms.ads.AdSize;
43-
import com.google.android.gms.ads.NativeExpressAdView;
42+
import com.google.android.gms.ads.AdView;
4443
import com.grarak.kerneladiutor.R;
4544
import com.grarak.kerneladiutor.utils.AppSettings;
4645
import com.grarak.kerneladiutor.utils.Utils;
@@ -57,91 +56,58 @@
5756
/**
5857
* Created by willi on 08.08.16.
5958
*/
60-
public class AdNativeExpress extends LinearLayout {
59+
public class AdLayout extends LinearLayout {
6160

6261
public static final String ADS_FETCH = "https://raw.githubusercontent.com/Grarak/KernelAdiutor/master/ads/ads.json";
63-
private static final int MAX_WIDTH = 1200;
64-
private static final int MIN_HEIGHT = 132;
6562

66-
private boolean mNativeLoaded;
67-
private boolean mNativeLoading;
68-
private boolean mNativeFailedLoading;
63+
private boolean mAdFailedLoading;
6964
private boolean mGHLoading;
7065
private boolean mGHLoaded;
7166
private View mProgress;
7267
private View mAdText;
73-
private FrameLayout mNativeAdLayout;
74-
private NativeExpressAdView mNativeExpressAdView;
7568
private AppCompatImageView mGHImage;
69+
private AdView mAdView;
7670

77-
public AdNativeExpress(Context context) {
71+
public AdLayout(Context context) {
7872
this(context, null);
7973
}
8074

81-
public AdNativeExpress(Context context, AttributeSet attrs) {
75+
public AdLayout(Context context, AttributeSet attrs) {
8276
this(context, attrs, 0);
8377
}
8478

85-
public AdNativeExpress(Context context, AttributeSet attrs, int defStyleAttr) {
79+
public AdLayout(Context context, AttributeSet attrs, int defStyleAttr) {
8680
super(context, attrs, defStyleAttr);
8781

8882
LayoutInflater.from(context).inflate(R.layout.ad_native_express_view, this);
89-
mNativeAdLayout = findViewById(R.id.ad_layout);
83+
FrameLayout mAdLayout = findViewById(R.id.ad_layout);
9084
mProgress = findViewById(R.id.progress);
9185
mAdText = findViewById(R.id.ad_text);
9286
mGHImage = findViewById(R.id.gh_image);
9387

9488
findViewById(R.id.remove_ad).setOnClickListener(v
9589
-> ViewUtils.dialogDonate(v.getContext()).show());
9690

97-
mNativeExpressAdView = new NativeExpressAdView(context);
98-
mNativeExpressAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
99-
ViewGroup.LayoutParams.WRAP_CONTENT));
100-
mNativeExpressAdView.setAdUnitId(getContext().getString(Utils.DARK_THEME ?
101-
R.string.native_express_id_dark : R.string.native_express_id_light));
102-
mNativeExpressAdView.setAdListener(new AdListener() {
103-
@Override
104-
public void onAdFailedToLoad(int i) {
105-
super.onAdFailedToLoad(i);
106-
mNativeLoading = false;
107-
mNativeLoaded = false;
108-
mNativeFailedLoading = true;
109-
loadGHAd();
110-
}
111-
91+
mAdView = new AdView(context);
92+
mAdView.setAdSize(AdSize.SMART_BANNER);
93+
mAdView.setAdUnitId("ca-app-pub-1851546461606210/7537613480");
94+
mAdView.setAdListener(new AdListener() {
11295
@Override
11396
public void onAdLoaded() {
11497
super.onAdLoaded();
115-
mNativeLoaded = true;
116-
mNativeLoading = false;
117-
mNativeFailedLoading = false;
98+
mAdFailedLoading = false;
11899
mProgress.setVisibility(GONE);
119-
mNativeAdLayout.addView(mNativeExpressAdView);
100+
mAdLayout.addView(mAdView);
120101
}
121-
});
122-
}
123102

124-
@Override
125-
protected void onLayout(boolean changed, int l, int t, int r, int b) {
126-
super.onLayout(changed, l, t, r, b);
127-
int width;
128-
if (mNativeLoading || (mNativeLoaded && !mNativeFailedLoading)
129-
|| (!mNativeLoaded && mNativeFailedLoading) ||
130-
(width = mNativeAdLayout.getWidth()) == 0) {
131-
return;
132-
}
133-
float deviceDensity = getResources().getDisplayMetrics().density;
134-
if (deviceDensity > 0) {
135-
loadNativeAd(width, deviceDensity);
136-
}
137-
}
138-
139-
private void loadNativeAd(int width, float deviceDensity) {
140-
float adWidth = width / deviceDensity;
141-
if (adWidth > MAX_WIDTH) adWidth = MAX_WIDTH;
142-
mNativeExpressAdView.setAdSize(new AdSize((int) adWidth, MIN_HEIGHT));
143-
mNativeLoading = true;
144-
mNativeExpressAdView.loadAd(new AdRequest.Builder().build());
103+
@Override
104+
public void onAdFailedToLoad(int i) {
105+
super.onAdFailedToLoad(i);
106+
mAdFailedLoading = true;
107+
loadGHAd();
108+
}
109+
});
110+
mAdView.loadAd(new AdRequest.Builder().build());
145111
}
146112

147113
private boolean isActivityDestroyed(Context context) {
@@ -158,7 +124,7 @@ private boolean isActivityDestroyed(Context context) {
158124
}
159125

160126
public void loadGHAd() {
161-
if (!mNativeFailedLoading || mGHLoading || mGHLoaded) {
127+
if (!mAdFailedLoading || mGHLoading || mGHLoaded) {
162128
return;
163129
}
164130
mGHLoading = true;
@@ -222,15 +188,15 @@ public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? s
222188
}
223189

224190
public void resume() {
225-
mNativeExpressAdView.resume();
191+
mAdView.resume();
226192
}
227193

228194
public void pause() {
229-
mNativeExpressAdView.pause();
195+
mAdView.pause();
230196
}
231197

232198
public void destroy() {
233-
mNativeExpressAdView.destroy();
199+
mAdView.destroy();
234200
}
235201

236202
public static class GHAds {

app/src/main/java/com/grarak/kerneladiutor/views/recyclerview/AdView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
import android.view.View;
2323

2424
import com.grarak.kerneladiutor.R;
25-
import com.grarak.kerneladiutor.views.AdNativeExpress;
25+
import com.grarak.kerneladiutor.views.AdLayout;
2626

2727
/**
2828
* Created by willi on 06.08.16.
2929
*/
3030
public class AdView extends RecyclerViewItem {
3131

32-
private AdNativeExpress mAd;
32+
private AdLayout mAd;
3333

3434
@Override
3535
public int getLayoutRes() {
@@ -38,7 +38,7 @@ public int getLayoutRes() {
3838

3939
@Override
4040
public void onCreateView(View view) {
41-
mAd = (AdNativeExpress) view;
41+
mAd = (AdLayout) view;
4242
setFullSpan(true);
4343

4444
super.onCreateView(view);
Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,49 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
4-
android:id="@+id/cardview"
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
53
android:layout_width="match_parent"
64
android:layout_height="wrap_content"
7-
android:orientation="vertical"
8-
app:cardCornerRadius="@dimen/cardview_radius"
9-
app:cardElevation="@dimen/cardview_elevation"
10-
app:cardUseCompatPadding="true">
5+
android:orientation="vertical">
116

12-
<LinearLayout
7+
<FrameLayout
138
android:layout_width="match_parent"
14-
android:layout_height="wrap_content"
15-
android:orientation="vertical">
9+
android:layout_height="50dp">
1610

1711
<FrameLayout
12+
android:id="@+id/ad_layout"
1813
android:layout_width="match_parent"
19-
android:layout_height="132dp">
14+
android:layout_height="match_parent" />
2015

21-
<FrameLayout
22-
android:id="@+id/ad_layout"
23-
android:layout_width="match_parent"
24-
android:layout_height="match_parent" />
25-
26-
<android.support.v7.widget.AppCompatImageView
27-
android:id="@+id/gh_image"
28-
android:layout_width="match_parent"
29-
android:layout_height="match_parent"
30-
android:adjustViewBounds="true"
31-
android:scaleType="fitCenter"
32-
android:visibility="gone" />
16+
<android.support.v7.widget.AppCompatImageView
17+
android:id="@+id/gh_image"
18+
android:layout_width="match_parent"
19+
android:layout_height="match_parent"
20+
android:adjustViewBounds="true"
21+
android:scaleType="fitCenter"
22+
android:visibility="gone" />
3323

34-
<TextView
35-
android:id="@+id/ad_text"
36-
android:layout_width="wrap_content"
37-
android:layout_height="wrap_content"
38-
android:layout_gravity="center"
39-
android:fontFamily="sans-serif-thin"
40-
android:gravity="center"
41-
android:padding="10dp"
42-
android:text="@string/ad_here"
43-
android:textSize="22sp"
44-
android:visibility="gone" />
24+
<TextView
25+
android:id="@+id/ad_text"
26+
android:layout_width="wrap_content"
27+
android:layout_height="wrap_content"
28+
android:layout_gravity="center"
29+
android:gravity="center"
30+
android:padding="10dp"
31+
android:text="@string/ad_here"
32+
android:textSize="18sp"
33+
android:visibility="gone" />
4534

46-
<ProgressBar
47-
android:id="@+id/progress"
48-
android:layout_width="wrap_content"
49-
android:layout_height="wrap_content"
50-
android:layout_gravity="center" />
51-
</FrameLayout>
35+
<ProgressBar
36+
android:id="@+id/progress"
37+
android:layout_width="wrap_content"
38+
android:layout_height="wrap_content"
39+
android:layout_gravity="center" />
40+
</FrameLayout>
5241

53-
<android.support.v7.widget.AppCompatButton
54-
android:id="@+id/remove_ad"
55-
android:layout_width="match_parent"
56-
android:layout_height="30dp"
57-
android:background="?attr/selectableItemBackground"
58-
android:text="@string/remove_ad"
59-
android:textColor="?attr/colorAccent" />
60-
</LinearLayout>
61-
</android.support.v7.widget.CardView>
42+
<android.support.v7.widget.AppCompatButton
43+
android:id="@+id/remove_ad"
44+
android:layout_width="match_parent"
45+
android:layout_height="20dp"
46+
android:background="?attr/selectableItemBackground"
47+
android:text="@string/remove_ad"
48+
android:textColor="?attr/colorAccent" />
49+
</LinearLayout>

app/src/main/res/layout/fragment_usage_view.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
android:layout_height="wrap_content"
3131
android:focusable="false"
3232
android:padding="3dp"
33-
android:textColor="@color/textcolor_dark"
3433
android:textSize="12sp" />
3534

3635
<TextView
@@ -40,7 +39,6 @@
4039
android:layout_gravity="center_horizontal"
4140
android:focusable="false"
4241
android:padding="3dp"
43-
android:textColor="@color/textcolor_dark"
4442
android:textSize="12sp" />
4543

4644
<TextView
@@ -50,6 +48,5 @@
5048
android:layout_gravity="end"
5149
android:focusable="false"
5250
android:padding="3dp"
53-
android:textColor="@color/textcolor_dark"
5451
android:textSize="12sp" />
5552
</FrameLayout>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<com.grarak.kerneladiutor.views.AdNativeExpress xmlns:android="http://schemas.android.com/apk/res/android"
2+
<com.grarak.kerneladiutor.views.AdLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="wrap_content" />

0 commit comments

Comments
 (0)