diff --git a/app/build.gradle b/app/build.gradle index 5a6be50..97c2572 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -99,7 +99,7 @@ dependencies { //消息组件 implementation 'org.greenrobot:eventbus:3.1.1' - implementation 'com.google.android.gms:play-services-ads:20.3.0' +// implementation 'com.google.android.gms:play-services-ads:20.3.0' } \ No newline at end of file diff --git a/app/libs/SAD-release-1.0.9.aar b/app/libs/SAD-release-1.0.9.aar deleted file mode 100644 index 77339b7..0000000 Binary files a/app/libs/SAD-release-1.0.9.aar and /dev/null differ diff --git a/app/src/main/java/com/ik/mboxlauncher/ui/ADSWindowManager.java b/app/src/main/java/com/ik/mboxlauncher/ui/ADSWindowManager.java index 066c99f..496f43f 100644 --- a/app/src/main/java/com/ik/mboxlauncher/ui/ADSWindowManager.java +++ b/app/src/main/java/com/ik/mboxlauncher/ui/ADSWindowManager.java @@ -12,10 +12,8 @@ import com.android.monitor.DataBeeObserver; import com.android.monitor.impl.EventFactory; import com.android.nebulasdk.ADManager; import com.android.util.LogUtils; -import com.ik.mboxlauncher.view.AdMultiView; import com.ik.mboxlauncher.view.MultiView; import com.ik.mboxlauncher.view.HomeMultiView; -import com.seraphic.ad.AdStateListener; import java.io.File; import java.util.List; @@ -101,9 +99,6 @@ public class ADSWindowManager implements HomeMultiView.MultiViewListener{ if(mMultiViewList!=null&¤tADIndex"+tmpfile.exists()); - if(tmpfile.exists()) { - Glide.with(mContext).load(tmpfile).placeholder(imageResId).into(img_view); - } - - } - - @Override - public void loadIamgeRes(String uri, int defaultImageId) { - - } - - @Override - public void loadDefaultImage(int resId) { - img_view.setImageResource(resId); - } - - @Override - public void resetView() { - //TODO 如果无需响应用户操作取消广告(即:广告可点击),删掉下方一行代码 -// stopAd(); - } - - @Override - public void stopView() { - LogUtils.loge( "stopView=====>"); - stopAd(); - if(mFullRootView.getVisibility()==VISIBLE){ - mFullRootView.setVisibility(GONE); - } - } - - @Override - public void releaseView() { - - } - - @Override - public void pauseView() { - - } - - @Override - public boolean isAdPlaying() { - return mAdState == AdStateListener.AD_PLAYING - || mAdState == AdStateListener.AD_LOADING - || mAdState == AdStateListener.AD_LOADED; - } - - - public void setFullRooView(ViewGroup fullRooView){ - mFullRootView = fullRooView; - } - - @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - if(mWidth == 0 || mHeight == 0) { - RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams(); - mWidth = getWidth(); - mHeight = getHeight(); - oldMarginstart =layoutParams.leftMargin; - oldMargintop =layoutParams.topMargin; - } - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - stopAd(); - } - - @SuppressLint("SoonBlockedPrivateApi") - private void hookWebView() { - int sdkInt = Build.VERSION.SDK_INT; - try { - Class factoryClass = Class.forName("android.webkit.WebViewFactory"); - Field field = factoryClass.getDeclaredField("sProviderInstance"); - field.setAccessible(true); - Object sProviderInstance = field.get(null); - if (sProviderInstance != null) { - LogUtils.logi("sProviderInstance isn't null"); - return; - } - Method getProviderClassMethod = null; - if (sdkInt > 22) { - getProviderClassMethod = factoryClass.getDeclaredMethod("getProviderClass"); - } else if (sdkInt == 22) { - getProviderClassMethod = factoryClass.getDeclaredMethod("getFactoryClass"); - } else { - LogUtils.logi("Don't need to Hook WebView"); - return; - } - getProviderClassMethod.setAccessible(true); - Class factoryProviderClass = (Class) getProviderClassMethod.invoke(factoryClass); - Class delegateClass = Class.forName("android.webkit.WebViewDelegate"); - Constructor delegateConstructor = delegateClass.getDeclaredConstructor(); - delegateConstructor.setAccessible(true); - if (sdkInt < 26) { //低于Android O版本 - Constructor providerConstructor = factoryProviderClass.getConstructor(delegateClass); - if (providerConstructor != null) { - providerConstructor.setAccessible(true); - sProviderInstance = providerConstructor.newInstance(delegateConstructor.newInstance()); - } - } else { - Field chromiumMethodName = factoryClass.getDeclaredField("CHROMIUM_WEBVIEW_FACTORY_METHOD"); - chromiumMethodName.setAccessible(true); - String chromiumMethodNameStr = (String) chromiumMethodName.get(null); - if (chromiumMethodNameStr == null) { - chromiumMethodNameStr = "create"; - } - Method staticFactory = factoryProviderClass.getMethod(chromiumMethodNameStr, delegateClass); - if (staticFactory != null) { - sProviderInstance = staticFactory.invoke(null, delegateConstructor.newInstance()); - } - } - - if (sProviderInstance != null) { - field.set("sProviderInstance", sProviderInstance); - LogUtils.logi("can use webview"); - } else { - LogUtils.logi("can not use webview"); - } - } catch (Exception e) { - } - } - - private void startAd(){ - if(mAdPlayManager != null){ - stopAd(); - } - mAdPlayManager = new AdPlayManager(mContext, AdPlayManager.TYPE_WITH_CONTAINER, - 0, adstate -> { - if(mMultiViewListener != null) { - int playState = Player.STATE_IDLE; - switch (adstate){ - case AdStateListener.AD_LOADING: - playState = Player.STATE_BUFFERING; - break; - case AdStateListener.AD_LOADED: - case AdStateListener.AD_PLAYING: - playState = Player.STATE_READY; - break; - case AdStateListener.AD_ERROR: - playState = adstate; - break; - case AdStateListener.AD_COMPLETE_ALL: - playState = Player.STATE_ENDED; - break; - } - LogUtils.loge("AdMultiView adstate ===>"+adstate); - if((mAdState == -1 || mAdState != adstate) && playState != Player.STATE_IDLE) { - mMultiViewListener.onPlaybackStateChanged(getId(), playState); - } - } - mAdState = adstate; - - if(adstate == AdStateListener.AD_COMPLETE_ALL||adstate == AdStateListener.AD_ERROR){ - if(isFullAdShow){ - isFullAdShow = false; - requestFocus(); - } - stopAd(); - } - }); //position 必填 - mAdPlayManager.setAdFullRootView(mFullRootView);//设置全屏的 ad root - if(isFocused()) {//焦点在当前view时,显示back提示 - mAdPlayManager.setNeedCancelTips(true); - } - mAdPlayManager.startAd(mAdRootView,0); - } - @Override - public void stopAd() { - LogUtils.loge( "stopAd=====>"); - if (mAdPlayManager != null) { - mAdPlayManager.stopAd(); - mAdPlayManager = null; - } - } - - @Override - public boolean onAdViewClick(){ - boolean isNeed = false; - if (mAdPlayManager != null) { - isNeed = mAdPlayManager.onAdViewClick(); - } - isFullAdShow = isNeed; - return isNeed; - } - public boolean onAdBackClick(){ - boolean isNeed = false; - //NOTE: 如果希望全局按back键取消广告,可以移除焦点判断 - if (isFocused() && mAdPlayManager != null) { - isNeed = mAdPlayManager.onAdBackClick(); - } - return isNeed; - } - - private boolean mGainFocus=false; - -// @Override -// protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) { -// super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); -// mGainFocus = gainFocus; -// -// if (gainFocus) { -// if(mAdPlayManager != null) { -// mAdPlayManager.setNeedCancelTips(true); -// } -// setBackgroundResource(R.drawable.app_item_border); -// setTranslationZ(10); -// setElevation(10); -// -// scaleView(1.05f); -// -//// ScaleAnimation anim = new ScaleAnimation(1f, 1.1f, 1f, 1.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); -//// anim.setZAdjustment(Animation.ZORDER_TOP); -//// anim.setDuration(animDuration); -//// anim.setFillAfter(true); -//// this.startAnimation(anim); -// this.bringToFront(); -// } else { -// if(mAdPlayManager != null) { -// mAdPlayManager.setNeedCancelTips(false); -// } -// setBackgroundResource(R.color.transparent_background); -// setTranslationZ(0); -// setElevation(0); -// scaleView(1.0f); -//// ScaleAnimation anim = new ScaleAnimation(1.1f, 1f, 1.1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); -//// anim.setZAdjustment(Animation.ZORDER_TOP); -//// anim.setDuration(animDuration); -//// anim.setFillAfter(true); -//// this.startAnimation(anim); -// } -// } - - @Override - protected void onFocusChanged(boolean gainFocus, int direction, @Nullable Rect previouslyFocusedRect) { - super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); -// int width = getWidth(); -// int height = getHeight(); - mGainFocus = gainFocus; - if(gainFocus){ - if(mAdPlayManager != null) { - mAdPlayManager.setNeedCancelTips(true); - } - setBackgroundResource(R.drawable.app_item_border); - setTranslationZ(8); - setElevation(8); - ValueAnimator animator = ValueAnimator.ofFloat(1f,1.1f); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) { - float scale = (float) valueAnimator.getAnimatedValue(); -// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams(); -// layoutParams.height = (int) (height*scale); -// layoutParams.width = (int) (width*scale); -// setLayoutParams(layoutParams); -// setScaleWithLayoutd(scale); - setScaleWithLayoutd(scale); - invalidate(); - } - }); - animator.setDuration(animDuration); - animator.start(); - this.bringToFront(); - }else { - if(mAdPlayManager != null) { - mAdPlayManager.setNeedCancelTips(false); - } - setBackgroundResource(R.color.transparent_background); - setTranslationZ(0); - setElevation(0); - ValueAnimator animator = ValueAnimator.ofFloat(1.1f, 1f); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(@NonNull ValueAnimator valueAnimator) { - float scale = (float) valueAnimator.getAnimatedValue(); -// RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams(); -// layoutParams.height = (int) (height*scale); -// layoutParams.width = (int) (width*scale); -// if(layoutParams.height < mHeight || layoutParams.width < mWidth){ -// layoutParams.height = mHeight; -// layoutParams.width = mWidth; -// } -// setLayoutParams(layoutParams); -// setScaleWithLayoutd(scale); - setScaleWithLayoutd(scale); - invalidate(); - } - }); - animator.setDuration(animDuration); - animator.start(); - } - } - - - // 缩放方法 - public void scaleView(float scale) { - setScaleX(scale); - setScaleY(scale); - setScaleWithLayoutd(scale); - invalidate(); // 可选,通常不需要 - } - - - // 或者如果需要同时改变布局大小 - public void setScaleWithLayoutd(float scale) { - RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams(); - int newWidth = (int) (mWidth * scale); - int newHeight = (int) (mHeight * scale); - - // 调整margin保持中心位置 - lp.leftMargin -= (newWidth - lp.width) / 2; - lp.topMargin -= (newHeight - lp.height) / 2; - - lp.width = newWidth; - lp.height = newHeight; - setLayoutParams(lp); - } - -// public void setScaleWithLayouts(float scale) { -// RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) getLayoutParams(); -// // 调整margin保持中心位置 -// lp.leftMargin -= (mWidth - lp.width) / 2; -// lp.topMargin -= (mWidth - lp.height) / 2; -// lp.width = mWidth; -// lp.height = mWidth; -// setLayoutParams(lp); -// } - - - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - LogUtils.loge("AdMultiView onKeyDown==>"+keyCode); - switch (keyCode){ - case KeyEvent.KEYCODE_BACK: - if(mGainFocus){ - onAdBackClick(); - return true; - } - break; - - - } - - return super.onKeyDown(keyCode, event); - } -} diff --git a/app/src/main/res/layout-sw480dp/layout_rect_group1.xml b/app/src/main/res/layout-sw480dp/layout_rect_group1.xml index 15b5a15..c3c0502 100644 --- a/app/src/main/res/layout-sw480dp/layout_rect_group1.xml +++ b/app/src/main/res/layout-sw480dp/layout_rect_group1.xml @@ -98,13 +98,13 @@ /> - diff --git a/app/src/main/res/layout-sw540dp/layout_rect_group1.xml b/app/src/main/res/layout-sw540dp/layout_rect_group1.xml index 8c4a2b0..147d552 100644 --- a/app/src/main/res/layout-sw540dp/layout_rect_group1.xml +++ b/app/src/main/res/layout-sw540dp/layout_rect_group1.xml @@ -98,13 +98,13 @@ /> - diff --git a/app/src/main/res/layout-sw720dp/layout_rect_group1.xml b/app/src/main/res/layout-sw720dp/layout_rect_group1.xml index 53d1578..0707df3 100644 --- a/app/src/main/res/layout-sw720dp/layout_rect_group1.xml +++ b/app/src/main/res/layout-sw720dp/layout_rect_group1.xml @@ -98,13 +98,13 @@ /> - diff --git a/app/src/main/res/layout/layout_rect_group1.xml b/app/src/main/res/layout/layout_rect_group1.xml index 730894b..e04240c 100644 --- a/app/src/main/res/layout/layout_rect_group1.xml +++ b/app/src/main/res/layout/layout_rect_group1.xml @@ -97,13 +97,13 @@ /> - diff --git a/mylibrary/src/main/java/com/android/nebulasdk/ADManager.java b/mylibrary/src/main/java/com/android/nebulasdk/ADManager.java index 20d8f7f..e632a65 100644 --- a/mylibrary/src/main/java/com/android/nebulasdk/ADManager.java +++ b/mylibrary/src/main/java/com/android/nebulasdk/ADManager.java @@ -364,9 +364,9 @@ public class ADManager implements DownLoadManeger.DownloadListener { LogUtils.loge("analysisResInfo AdType===>"+adinfo.getAdType()); if(ADTYPE_VIDEO.equals(adinfo.getAdType())){ - if(adinfo.getAdUri()!=null&&adinfo.getAdSize()!=null) { - addDownloadTask(adsInfoBean, adinfo.getAdUri(), 0, adinfo.getAdSize()); - } +// if(adinfo.getAdUri()!=null&&adinfo.getAdSize()!=null) { +// addDownloadTask(adsInfoBean, adinfo.getAdUri(), 0, adinfo.getAdSize()); +// } }else if(ADTYPE_FAV.equals(adinfo.getAdType())){ if( adinfo.getInfo()!=null){ String[] packageArray =adinfo.getInfo().split(",");