Skip to content

Commit

Permalink
Fixed build warnings and imports.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 590249446
  • Loading branch information
nventimigli authored and maddevrelgithubbot committed Dec 12, 2023
1 parent 981505a commit 4648acf
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package com.google.android.gms.example.appopendemo;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

/** Main activity in the app. */
public class MainActivity extends AppCompatActivity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Lifecycle.Event;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.ProcessLifecycleOwner;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.FullScreenContentCallback;
Expand All @@ -38,7 +37,7 @@

/** Application class that initializes, loads and show ads when activities change states. */
public class MyApplication extends Application
implements ActivityLifecycleCallbacks, LifecycleObserver {
implements ActivityLifecycleCallbacks, DefaultLifecycleObserver {

private AppOpenAdManager appOpenAdManager;
private Activity currentActivity;
Expand All @@ -54,9 +53,9 @@ public void onCreate() {
}

/** LifecycleObserver method that shows the app open ad when the app moves to foreground. */
@OnLifecycleEvent(Event.ON_START)
protected void onMoveToForeground() {
// Show the ad (if available) when the app moves to foreground.
@Override
public void onStart(@NonNull LifecycleOwner owner) {
DefaultLifecycleObserver.super.onStart(owner);
appOpenAdManager.showAdIfAvailable(currentActivity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package com.google.android.gms.example.appopendemo;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.example.appopendemo.MyApplication.OnShowAdCompleteListener;
import java.util.concurrent.TimeUnit;
Expand All @@ -47,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_splash);

// Create a timer so the SplashActivity will be displayed for a fixed amount of time.
createTimer(COUNTER_TIME_MILLISECONDS);
createTimer();

googleMobileAdsConsentManager =
GoogleMobileAdsConsentManager.getInstance(getApplicationContext());
Expand Down Expand Up @@ -77,22 +78,20 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

/**
* Create the countdown timer, which counts down to zero and show the app open ad.
*
* @param time the number of milliseconds that the timer counts down from
*/
private void createTimer(long time) {
/** Create the countdown timer, which counts down to zero and show the app open ad. */
private void createTimer() {
final TextView counterTextView = findViewById(R.id.timer);

CountDownTimer countDownTimer =
new CountDownTimer(time, 1000) {
new CountDownTimer(SplashActivity.COUNTER_TIME_MILLISECONDS, 1000) {
@SuppressLint("SetTextI18n")
@Override
public void onTick(long millisUntilFinished) {
secondsRemaining = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) + 1;
counterTextView.setText("App is done loading in: " + secondsRemaining);
}

@SuppressLint("SetTextI18n")
@Override
public void onFinish() {
secondsRemaining = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.android.gms.example.bannerexample;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
Expand All @@ -27,6 +26,7 @@
import android.widget.FrameLayout;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.RequestConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -28,6 +27,7 @@
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
Expand Down Expand Up @@ -244,8 +244,11 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
adIsLoading = false;
String error =
String.format(
java.util.Locale.US,
"domain: %s, code: %d, message: %s",
loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage());
loadAdError.getDomain(),
loadAdError.getCode(),
loadAdError.getMessage());
Toast.makeText(
MyActivity.this, "onAdFailedToLoad() with error: " + error, Toast.LENGTH_SHORT)
.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -32,6 +31,7 @@
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdLoader;
import com.google.android.gms.ads.LoadAdError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.AlertDialog;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

/**
* A dialog fragment to inform the users about an upcoming interstitial video ad and let the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -14,6 +13,7 @@
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package com.google.android.gms.example.appopenexample;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

/** Main activity in the app. */
public class MainActivity extends AppCompatActivity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package com.google.android.gms.example.appopenexample;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import androidx.appcompat.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.example.appopenexample.MyApplication.OnShowAdCompleteListener;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -87,12 +88,14 @@ private void createTimer(long time) {

CountDownTimer countDownTimer =
new CountDownTimer(time, 1000) {
@SuppressLint("SetTextI18n")
@Override
public void onTick(long millisUntilFinished) {
secondsRemaining = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) + 1;
counterTextView.setText("App is done loading in: " + secondsRemaining);
}

@SuppressLint("SetTextI18n")
@Override
public void onFinish() {
secondsRemaining = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.google.android.gms.example.bannerexample;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
Expand All @@ -27,6 +26,7 @@
import android.widget.FrameLayout;
import android.widget.PopupMenu;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
Expand Down
10 changes: 6 additions & 4 deletions java/admob/FullScreenNativeExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ apply plugin: "com.android.application"

android {
namespace "com.google.example.gms.fullscreennativeexample"
compileSdkVersion 34
compileSdk 34
defaultConfig {
applicationId "com.google.android.gms.example.fullscreennativeexample"
minSdkVersion 19
multiDexEnabled = true
targetSdkVersion 34
versionCode 1
versionName "1.0"
Expand All @@ -24,6 +23,9 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'com.google.android.exoplayer:exoplayer:2.18.6'
implementation 'com.google.android.gms:play-services-ads:22.6.0'
implementation 'androidx.media3:media3-exoplayer:1.2.0'
implementation 'androidx.media3:media3-exoplayer-dash:1.2.0'
implementation 'androidx.media3:media3-ui:1.2.0'
implementation "androidx.media3:media3-session:1.2.0"
implementation 'com.google.android.gms:play-services-ads:22.5.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:name="androidx.multidex.MultiDexApplication"
android:roundIcon="@mipmap/ic_launcher_round"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@

package com.google.example.gms.fullscreennativeexample;

import static com.google.android.exoplayer2.ExoPlayerLibraryInfo.TAG;
import static android.content.ContentValues.TAG;

import android.net.Uri;
import android.util.Log;
import android.view.View;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import androidx.annotation.OptIn;
import androidx.media3.common.MediaItem;
import androidx.media3.common.Player;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.RawResourceDataSource;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.ui.PlayerView;
import com.google.example.gms.fullscreennativeexample.FeedAdapter.ContentFeedItem;

/** A ViewHolder representing video content. */
public class ContentViewHolder extends FeedViewHolder {
private final PlayerView playerView;
private final SimpleExoPlayer player;
private final ExoPlayer player;

public ContentViewHolder(View itemView) {
super(itemView);
Expand All @@ -44,7 +46,7 @@ public void onClick(View view) {
}
});

player = new SimpleExoPlayer.Builder(itemView.getContext()).build();
player = new ExoPlayer.Builder(itemView.getContext()).build();
player.setRepeatMode(Player.REPEAT_MODE_ALL);
playerView = (PlayerView) itemView.findViewById(R.id.player_view);
playerView.setPlayer(player);
Expand Down Expand Up @@ -76,6 +78,7 @@ public PlayerView getPlayerView() {
}

/** Expecting the id of raw resource video file. */
@OptIn(markerClass = UnstableApi.class)
public void bind(ContentFeedItem contentFeedItem, int position) {
Player player = this.getPlayer();
Uri uri = RawResourceDataSource.buildRawResourceUri(contentFeedItem.getResourceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.google.example.gms.fullscreennativeexample;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.gms.ads.nativead.NativeAd;
import java.util.ArrayList;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package com.google.example.gms.fullscreennativeexample;

import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;

/** ViewHolder instance which holds the actual feed. */
public abstract class FeedViewHolder extends RecyclerView.ViewHolder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package com.google.example.gms.fullscreennativeexample;

import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import com.google.example.gms.fullscreennativeexample.FeedAdapter.AdFeedItem;
import com.google.example.gms.fullscreennativeexample.NativeAdsPool.OnPoolRefreshedListener;

Expand Down Expand Up @@ -60,7 +60,8 @@ public View onCreateView(
nativeAdsPool = new NativeAdsPool(this.getContext());
nativeAdsPool.init(
(OnPoolRefreshedListener) () -> feedAdapter.add(new AdFeedItem(nativeAdsPool.pop())));
nativeAdsPool.refresh(/* numOfAds= */ 5);
// numOfAds=
nativeAdsPool.refresh(5);
return rootView;
}
}
Loading

0 comments on commit 4648acf

Please sign in to comment.