From 760aee20870a34e6130a1c12237c5b747e2b00bd Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 28 一月 2022 12:58:40 +0800 Subject: [PATCH] 隐私合规,青少年模式,64位兼容 --- MGVideo/src/com/mugua/mgvideo/ui/main/MainActivity.java | 249 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 218 insertions(+), 31 deletions(-) diff --git a/MGVideo/src/com/mugua/mgvideo/ui/main/MainActivity.java b/MGVideo/src/com/mugua/mgvideo/ui/main/MainActivity.java index 72f59e6..f71702a 100644 --- a/MGVideo/src/com/mugua/mgvideo/ui/main/MainActivity.java +++ b/MGVideo/src/com/mugua/mgvideo/ui/main/MainActivity.java @@ -11,32 +11,51 @@ import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.Configuration; import android.database.Cursor; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; +import androidx.fragment.app.Fragment; import androidx.loader.app.LoaderManager; import androidx.loader.content.CursorLoader; import androidx.loader.content.Loader; import android.telephony.TelephonyManager; +import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.RadioGroup.OnCheckedChangeListener; +import android.widget.Toast; +import com.bytedance.novel.pangolin.NovelSDK; +import com.bytedance.sdk.dp.DPSdk; +import com.bytedance.sdk.dp.DPWidgetDrawParams; +import com.bytedance.sdk.dp.DPWidgetNewsParams; +import com.bytedance.sdk.dp.IDPDrawListener; +import com.bytedance.sdk.dp.IDPNewsListener; +import com.bytedance.sdk.dp.IDPWidget; +import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd; import com.lcjian.library.DeviceUuidFactory; import com.lcjian.library.util.FragmentSwitchHelper; +import com.lcjian.library.util.FragmentSwitchHelperV2; import com.lcjian.library.util.common.DimenUtils; import com.lcjian.library.util.common.StringUtils; import com.mozillaonline.providers.downloads.DownloadService; import com.mugua.mgvideo.R; +import com.mugua.mgvideo.entity.HomeNavType; import com.mugua.mgvideo.entity.recommend.HomeClass; +import com.mugua.mgvideo.util.ad.FullVideoAdManager; +import com.mugua.mgvideo.util.ad.InterstitialAdUtil; import com.umeng.socialize.UMShareAPI; +import com.yeshi.base.entity.ad.AdPositionEnum; import com.yeshi.base.utils.YouthUtil; +import com.yeshi.base.utils.ad.AdTypeEnum; +import com.yeshi.base.utils.ad.AdUtil; import com.yeshi.base.utils.http.BasicTextHttpResponseHandler; import com.mugua.mgvideo.MGVideoAPI; import com.mugua.mgvideo.MGVideoApplication; @@ -56,7 +75,9 @@ import java.io.BufferedReader; import java.io.InputStreamReader; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import de.greenrobot.event.EventBus; @@ -64,13 +85,101 @@ public class MainActivity extends BaseActivity implements LoaderManager.LoaderCallbacks<Cursor> { + private static final String TAG = "MainActivity"; private RadioGroup rg_nav; private BadgeView mBadgeView; - private FragmentSwitchHelper mFragmentSwitchHelper; + private FragmentSwitchHelperV2 mFragmentSwitchHelper; private ProgressDialog pd = null; + + + private void initFragment() { + mFragmentSwitchHelper = FragmentSwitchHelperV2.create(R.id.fl_main_fragment_container, getSupportFragmentManager(), null); + HomeClass homeClass = new HomeClass(); + homeClass.setDataKey("recommend"); + homeClass.setId("1626144258979"); + homeClass.setDataType("recommend"); + + mFragmentSwitchHelper.addFragment(HomeNavType.recommend.name(), RecommendNewFragment.newInstance(homeClass, 0)); + mFragmentSwitchHelper.addFragment(HomeNavType.category.name(), CategoryFragment.newInstance(true)); + mFragmentSwitchHelper.addFragment(HomeNavType.shop.name(), ShopFragment.newInstance(true)); + mFragmentSwitchHelper.addFragment(HomeNavType.mine.name(), new MineFragment()); + + if (AdUtil.isCanInitCSJ()) { + + //灏忚 + mFragmentSwitchHelper.addFragment(HomeNavType.novel.name(), new NovelFragment(getSupportFragmentManager())); + + + //灏忚棰� + mFragmentSwitchHelper.addFragment(HomeNavType.drawVideo.name(), new DYVideoFragment()); + + //璧勮 + mFragmentSwitchHelper.addFragment(HomeNavType.news.name(), new DYNewsFragment()); + + } + + } + + //搴曢儴瀵艰埅鑿滃崟鏄剧ず + private void setNavShow() { + if (YouthUtil.isOpenYouthMode(getApplicationContext())) { + findViewById(R.id.rb_nav_draw_video).setVisibility(View.GONE); + findViewById(R.id.rb_nav_category).setVisibility(View.GONE); + findViewById(R.id.rb_shop).setVisibility(View.GONE); + findViewById(R.id.rb_nav_watch).setVisibility(View.GONE); + findViewById(R.id.rb_nav_novel).setVisibility(View.GONE); + } else { + //鍚庡彴鎺у埗鏄剧ず鑿滃崟 + if (AdUtil.isCanInitCSJ() && AdUtil.getAdType(getApplicationContext(), AdPositionEnum.splashHotStart) != null) { + findViewById(R.id.rb_nav_draw_video).setVisibility(View.VISIBLE); + findViewById(R.id.rb_nav_watch).setVisibility(View.VISIBLE); + findViewById(R.id.rb_nav_novel).setVisibility(View.VISIBLE); + findViewById(R.id.rb_nav_category).setVisibility(View.GONE); + findViewById(R.id.rb_shop).setVisibility(View.GONE); + } else { + findViewById(R.id.rb_nav_draw_video).setVisibility(View.GONE); + findViewById(R.id.rb_nav_watch).setVisibility(View.GONE); + findViewById(R.id.rb_nav_novel).setVisibility(View.GONE); + findViewById(R.id.rb_nav_category).setVisibility(View.VISIBLE); + findViewById(R.id.rb_shop).setVisibility(View.VISIBLE); + } + } + } + + private Runnable adCallback; + + //鏄剧ず鎻掑睆骞垮憡 + private void showInterstitialAd() { + + final AdTypeEnum adType = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.homeInterstitial); + if (adType == null) { + return; + } + + adCallback = new Runnable() { + @Override + public void run() { + AdTypeEnum type = adType; + //Android 5.0浠ヤ笅骞垮憡鍏煎 + if (type == AdTypeEnum.csj && !AdUtil.isCanInitCSJ()) { + type = AdTypeEnum.gdt; + } + + if (type == AdTypeEnum.csj) { + InterstitialAdUtil.showAd(MainActivity.this, type, getString(R.string.ad_csj_pid_home_insert)); + } else { + InterstitialAdUtil.showAd(MainActivity.this, type, getString(R.string.ad_gdt_pid_home_insert)); + } + + + } + }; + //寤惰繜涓夌鏄剧ず + rg_nav.postDelayed(adCallback, 3000); + } @Override protected void onCreate(Bundle savedInstanceState) { @@ -103,14 +212,9 @@ pd.setMessage("姝e湪璇锋眰缃戠粶..."); pd.setCanceledOnTouchOutside(false); - HomeClass homeClass = new HomeClass(); - homeClass.setDataKey("recommend"); - homeClass.setId("1626144258979"); - homeClass.setDataType("recommend"); - mFragmentSwitchHelper = FragmentSwitchHelper.create( - R.id.fl_main_fragment_container, getSupportFragmentManager(), - RecommendNewFragment.newInstance(homeClass, 0), BaiDuVideosFragment.newInstance(), new CategoryFragment(), - new ShopFragment(), new MineFragment()); + + initFragment(); + rg_nav = findViewById(R.id.rg_nav); rg_nav.setOnCheckedChangeListener(new OnCheckedChangeListener() { @@ -119,32 +223,44 @@ switch (checkedId) { case R.id.rb_nav_recommend: { mFragmentSwitchHelper - .changeFragment(RecommendNewFragment.class); + .changeFragment(HomeNavType.recommend.name()); } break; - case R.id.rb_nav_short_video: + case R.id.rb_nav_draw_video: { mFragmentSwitchHelper - .changeFragment(BaiDuVideosFragment.class); - break; + .changeFragment(HomeNavType.drawVideo.name()); + } + break; case R.id.rb_nav_category: { mFragmentSwitchHelper - .changeFragment(CategoryFragment.class); + .changeFragment(HomeNavType.category.name()); } + break; + case R.id.rb_nav_novel: { + mFragmentSwitchHelper + .changeFragment(HomeNavType.novel.name()); + } + break; + + case R.id.rb_nav_watch: { + mFragmentSwitchHelper + .changeFragment(HomeNavType.news.name()); + } break; case R.id.rb_shop: { - mFragmentSwitchHelper.changeFragment(ShopFragment.class); + mFragmentSwitchHelper.changeFragment(HomeNavType.shop.name()); } break; case R.id.rb_nav_mine: { - mFragmentSwitchHelper.changeFragment(MineFragment.class); + mFragmentSwitchHelper.changeFragment(HomeNavType.mine.name()); } break; } } }); mBadgeView = new BadgeView(this, rg_nav); - mBadgeView.setBackgroundResource(R.drawable.ic_red_dot); + mBadgeView.setBackgroundResource(R.drawable.app_icon); mBadgeView.setTextSize(1); mBadgeView.setText(""); mBadgeView.setBadgeMargin(DimenUtils.dipToPixels(24, this), @@ -166,6 +282,8 @@ AppUpdate.setAppUpdateKey(map.get("GuanWang")); } AppUpdate.initAppUpdate(); + + showInterstitialAd(); } private String getChannelName() { @@ -245,6 +363,7 @@ @Override public void onResume() { super.onResume(); + setNavShow(); EventBus.getDefault().register(this); SharedPreferences preferences = getSharedPreferences("user", Context.MODE_PRIVATE); @@ -253,17 +372,6 @@ if (isLogin) { getNewInfo(); } - - if (YouthUtil.isOpenYouthMode(getApplicationContext())) { - findViewById(R.id.rb_nav_short_video).setVisibility(View.GONE); - findViewById(R.id.rb_nav_category).setVisibility(View.GONE); - findViewById(R.id.rb_shop).setVisibility(View.GONE); - } else { - findViewById(R.id.rb_nav_short_video).setVisibility(View.GONE); - findViewById(R.id.rb_nav_category).setVisibility(View.VISIBLE); - findViewById(R.id.rb_shop).setVisibility(View.VISIBLE); - } - } @Override @@ -271,6 +379,7 @@ super.onPause(); EventBus.getDefault().unregister(this); } + @Override protected void onActivityResult(int arg0, int arg1, Intent arg2) { @@ -566,9 +675,14 @@ protected void onDestroy() { super.onDestroy(); AppUpdate.destoryAppUpdate(); + if (rg_nav != null && adCallback != null) { + rg_nav.removeCallbacks(adCallback); + } } private long mExitTime; + + boolean showFullAd = false; @Override public boolean onKeyDown(int keyCode, KeyEvent event) { @@ -578,9 +692,76 @@ // mExitTime = System.currentTimeMillis(); // return true; // } - ExitDialog dialog = new ExitDialog.Builder(this).create(); - dialog.setCanceledOnTouchOutside(true); - dialog.show(); + //exit + AdTypeEnum adType = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.exitAppFullvideo); + if (adType != null) { + + if (showFullAd) { + finish(); + return true; + } + + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH) { + adType = AdTypeEnum.gdt; + } + + + if (adType == AdTypeEnum.csj) { + FullVideoAdManager.getInstance().loadAd(MainActivity.this, AdTypeEnum.csj,getString(R.string.ad_csj_pid_video_detail_fullvideo), new FullVideoAdManager.IFullVideoAdListener() { + @Override + public void onFail(String msg) { + showFullAd = true; + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(), "鍐嶆寜涓�娆¢��鍑哄簲鐢�", Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public void onFinish() { + showFullAd = true; + runOnUiThread(new Runnable() { + @Override + public void run() { + MainActivity.this.finish(); + } + }); + } + + }); + } else { + FullVideoAdManager.getInstance().loadAd(MainActivity.this, AdTypeEnum.gdt, getString(R.string.ad_gdt_pid_video_detail_insert), new FullVideoAdManager.IFullVideoAdListener() { + @Override + public void onFail(String msg) { + showFullAd = true; + runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(), "鍐嶆寜涓�娆¢��鍑哄簲鐢�", Toast.LENGTH_SHORT).show(); + } + }); + } + + @Override + public void onFinish() { + showFullAd = true; + runOnUiThread(new Runnable() { + @Override + public void run() { + MainActivity.this.finish(); + } + }); + } + + }); + } + } else { + ExitDialog dialog = new ExitDialog.Builder(this).create(); + dialog.setCanceledOnTouchOutside(true); + dialog.show(); + } return true; } return super.onKeyDown(keyCode, event); @@ -591,4 +772,10 @@ Intent intent = new Intent(MainActivity.this, DownloadService.class); startService(intent); } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + Log.i(TAG,"onConfigurationChanged"); + } } -- Gitblit v1.8.0