|
1 | 1 | package com.pypisan.kinani.view;
|
2 | 2 |
|
| 3 | +import android.animation.Animator; |
| 4 | +import android.animation.AnimatorListenerAdapter; |
| 5 | +import android.animation.ObjectAnimator; |
3 | 6 | import android.content.Intent;
|
4 | 7 | import android.database.Cursor;
|
| 8 | +import android.graphics.drawable.ColorDrawable; |
5 | 9 | import android.os.Bundle;
|
6 | 10 | import android.util.Log;
|
7 | 11 | import android.view.LayoutInflater;
|
8 | 12 | import android.view.View;
|
9 | 13 | import android.view.ViewGroup;
|
| 14 | +import android.view.animation.AccelerateDecelerateInterpolator; |
| 15 | +import android.view.animation.DecelerateInterpolator; |
| 16 | +import android.widget.Button; |
10 | 17 | import android.widget.ImageView;
|
11 | 18 | import android.widget.LinearLayout;
|
12 | 19 | import android.widget.RelativeLayout;
|
|
22 | 29 | import androidx.recyclerview.widget.RecyclerView;
|
23 | 30 |
|
24 | 31 | import com.facebook.shimmer.ShimmerFrameLayout;
|
| 32 | +import com.google.android.ads.nativetemplates.NativeTemplateStyle; |
| 33 | +import com.google.android.ads.nativetemplates.TemplateView; |
| 34 | +import com.google.android.gms.ads.AdLoader; |
25 | 35 | import com.google.android.gms.ads.AdRequest;
|
26 | 36 | import com.google.android.gms.ads.AdView;
|
27 |
| -import com.inmobi.ads.InMobiBanner; |
| 37 | +import com.google.android.gms.ads.MobileAds; |
| 38 | +import com.google.android.gms.ads.nativead.NativeAd; |
28 | 39 | import com.pypisan.kinani.R;
|
29 | 40 | import com.pypisan.kinani.adapter.ContinueWatchingAdapter;
|
30 | 41 | import com.pypisan.kinani.adapter.HomeViewAdapter;
|
@@ -114,12 +125,57 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
|
114 | 125 | ImageView trendingMore = view.findViewById(R.id.trending_more);
|
115 | 126 | ImageView recommendationMore = view.findViewById(R.id.recommended_more);
|
116 | 127 |
|
| 128 | +// Activating Animation |
| 129 | + LinearLayout frontCard = view.findViewById(R.id.frontView); |
| 130 | + LinearLayout backCard = view.findViewById(R.id.backView); |
| 131 | + Button seeAnswer = view.findViewById(R.id.unknown_button); |
| 132 | + |
| 133 | + seeAnswer.setOnClickListener(new View.OnClickListener() { |
| 134 | + @Override |
| 135 | + public void onClick(View v) { |
| 136 | + final ObjectAnimator oa1 = ObjectAnimator.ofFloat(frontCard, "scaleX", 1f, 0f); |
| 137 | + final ObjectAnimator oa2 = ObjectAnimator.ofFloat(backCard, "scaleX", 0f, 1f); |
| 138 | + oa1.setInterpolator(new DecelerateInterpolator()); |
| 139 | + oa2.setInterpolator(new AccelerateDecelerateInterpolator()); |
| 140 | + oa1.addListener(new AnimatorListenerAdapter() { |
| 141 | + @Override |
| 142 | + public void onAnimationEnd(Animator animation) { |
| 143 | + super.onAnimationEnd(animation); |
| 144 | + backCard.setVisibility(View.VISIBLE); |
| 145 | + oa2.start(); |
| 146 | + } |
| 147 | + }); |
| 148 | + oa1.start(); |
| 149 | + oa1.setDuration(300); |
| 150 | + oa2.setDuration(300); |
| 151 | + } |
| 152 | + }); |
| 153 | + |
117 | 154 | // Ads
|
118 |
| - InMobiBanner bannerAdTop = (InMobiBanner) view.findViewById(R.id.banner); |
119 |
| - InMobiBanner bannerAdBottom = (InMobiBanner) view.findViewById(R.id.banner2); |
| 155 | + AdView bannerAdTop = view.findViewById(R.id.banner); |
| 156 | + AdView bannerAdBottom = view.findViewById(R.id.banner2); |
120 | 157 | AdView googleAdView = view.findViewById(R.id.gadView);
|
121 |
| - AdRequest adRequest = new AdRequest.Builder().build(); |
122 |
| - googleAdView.loadAd(adRequest); |
| 158 | + googleAdView.loadAd(new AdRequest.Builder().build()); |
| 159 | + bannerAdBottom.loadAd(new AdRequest.Builder().build()); |
| 160 | + bannerAdTop.loadAd(new AdRequest.Builder().build()); |
| 161 | + |
| 162 | +// Native Ad |
| 163 | + MobileAds.initialize(getContext()); |
| 164 | + AdLoader adLoader = new AdLoader.Builder(getContext(), "ca-app-pub-3251882712461623/7937761777") |
| 165 | + .forNativeAd(new NativeAd.OnNativeAdLoadedListener() { |
| 166 | + @Override |
| 167 | + public void onNativeAdLoaded(NativeAd nativeAd) { |
| 168 | + ColorDrawable background = ((ColorDrawable)frontCard.getBackground()); |
| 169 | + NativeTemplateStyle styles = new |
| 170 | + NativeTemplateStyle.Builder().withMainBackgroundColor(background).build(); |
| 171 | + TemplateView template = view.findViewById(R.id.my_template_ad); |
| 172 | + template.setStyles(styles); |
| 173 | + template.setNativeAd(nativeAd); |
| 174 | + } |
| 175 | + }) |
| 176 | + .build(); |
| 177 | + |
| 178 | + adLoader.loadAd(new AdRequest.Builder().build()); |
123 | 179 |
|
124 | 180 | // Starting Shimmer Effect
|
125 | 181 | containerRecent.startShimmer();
|
@@ -255,8 +311,6 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
255 | 311 |
|
256 | 312 | // Setting Data
|
257 | 313 | scheduleAdapter = new RecentlyAiredAdapter(animeScheduleListInc, getContext(), this::onItemClicked);
|
258 |
| - bannerAdTop.load(); |
259 |
| - bannerAdBottom.load(); |
260 | 314 |
|
261 | 315 | // Continue Watching Recycler
|
262 | 316 | recyclerView_continue = view.findViewById(R.id.home_recycler_view_continue_watching);
|
|
0 commit comments