From dc7ea9818c143e98ce89ac27c3f54ff9b252126b Mon Sep 17 00:00:00 2001 From: Max Lv Date: Tue, 1 Oct 2013 09:37:26 +0800 Subject: [PATCH] fix AdView --- src/main/res/xml/pref_feature.xml | 3 +- .../com/github/shadowsocks/Shadowsocks.scala | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/res/xml/pref_feature.xml b/src/main/res/xml/pref_feature.xml index 38fc6f2b..b971142a 100755 --- a/src/main/res/xml/pref_feature.xml +++ b/src/main/res/xml/pref_feature.xml @@ -32,6 +32,7 @@ android:summary="@string/auto_connect_summary" android:title="@string/auto_connect"> - + + diff --git a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala index da1354cd..5eb62008 100644 --- a/src/main/scala/com/github/shadowsocks/Shadowsocks.scala +++ b/src/main/scala/com/github/shadowsocks/Shadowsocks.scala @@ -45,7 +45,7 @@ import android.graphics.{Color, Bitmap, Typeface} import android.os._ import android.preference._ import android.util.Log -import android.view.{View, ViewGroup, ViewParent, KeyEvent} +import android.view._ import android.widget._ import com.google.analytics.tracking.android.EasyTracker import de.keyboardsurfer.android.widget.crouton.Crouton @@ -75,6 +75,9 @@ import com.github.shadowsocks.preferences.{ProfileEditTextPreference, PasswordEd import com.github.shadowsocks.database.Item import com.github.shadowsocks.database.Category import scala.Option +import android.view.ViewGroup.LayoutParams +import com.github.shadowsocks.database.Item +import com.github.shadowsocks.database.Category class ProfileIconDownloader(context: Context, connectTimeout: Int, readTimeout: Int) extends BaseImageDownloader(context, connectTimeout, readTimeout) { @@ -460,18 +463,21 @@ class Shadowsocks } } - def initAdView(layoutResId: Int) { + def initAdView() { if (settings.getString(Key.proxy, "") == "198.199.101.152") { - val adView = { - if (isSinglePane) { - new AdView(this, AdSize.SMART_BANNER, "a151becb8068b09") - } else { - new AdView(this, AdSize.BANNER, "a151becb8068b09") - } - } - val layoutView = findViewById(layoutResId).asInstanceOf[ViewGroup] + val layoutView = drawer.getContentContainer if (layoutView != null) { - layoutView.addView(adView, 0) + val adView = { + if (isSinglePane) { + new AdView(this, AdSize.SMART_BANNER, "a151becb8068b09") + } else { + new AdView(this, AdSize.BANNER, "a151becb8068b09") + } + } + val params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) + params.gravity = Gravity.BOTTOM + adView.setLayoutParams(params) + layoutView.asInstanceOf[ViewGroup].addView(adView, 0) adView.loadAd(new AdRequest) } } @@ -479,7 +485,7 @@ class Shadowsocks override def setContentView(layoutResId: Int) { drawer.setContentView(layoutResId) - initAdView(layoutResId) + initAdView() onContentChanged() } @@ -496,7 +502,6 @@ class Shadowsocks menuAdapter.setListener(this) listView.setAdapter(menuAdapter) drawer.setMenuView(listView) - // The drawable that replaces the up indicator in the action bar drawer.setSlideDrawable(R.drawable.ic_drawer) // Whether the previous drawable should be shown