From e079ef31a93ef13d7cc2cb48149b92d965fd8280 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sun, 8 Nov 2015 23:07:10 +0800 Subject: [PATCH] fix AdView --- src/main/res/layout/layout_main_ad.xml | 36 +++++++++++++++++++ .../com/github/shadowsocks/Shadowsocks.scala | 28 ++++----------- 2 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 src/main/res/layout/layout_main_ad.xml diff --git a/src/main/res/layout/layout_main_ad.xml b/src/main/res/layout/layout_main_ad.xml new file mode 100644 index 00000000..067e6416 --- /dev/null +++ b/src/main/res/layout/layout_main_ad.xml @@ -0,0 +1,36 @@ + + + + + + + + + + diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index c1497c39..64c167aa 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -413,28 +413,8 @@ class Shadowsocks } } - def initAdView() { - if (settings.getString(Key.proxy, "") == "198.199.101.152") { - val layoutView = { - if (Build.VERSION.SDK_INT > 10) { - drawer.getContentContainer.getChildAt(0) - } else { - getLayoutView(drawer.getContentContainer.getParent) - } - } - if (layoutView != null) { - val adView = new AdView(this) - adView.setAdUnitId("ca-app-pub-9097031975646651/7760346322") - adView.setAdSize(AdSize.SMART_BANNER) - layoutView.asInstanceOf[ViewGroup].addView(adView, 0) - adView.loadAd(new AdRequest.Builder().build()) - } - } - } - override def setContentView(layoutResId: Int) { drawer.setContentView(layoutResId) - initAdView() onContentChanged() } @@ -442,7 +422,13 @@ class Shadowsocks super.onCreate(savedInstanceState) - setContentView(R.layout.layout_main) + if (settings.getString(Key.proxy, "") == "198.199.101.152") { + setContentView(R.layout.layout_main_ad) + val adView = findViewById(R.id.adView).asInstanceOf[AdView] + adView.loadAd(new AdRequest.Builder().build()) + } else { + setContentView(R.layout.layout_main) + } // Update the profile if (!status.getBoolean(getVersionName, false)) {