Commit aa1e052b authored by Max Lv's avatar Max Lv

Add native adview

parent 7564ba51
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<!-- Based on: https://github.com/android/platform_frameworks_base/blob/505e3ab/core/res/res/layout/simple_list_item_2.xml --> <!-- Based on: https://github.com/android/platform_frameworks_base/blob/505e3ab/core/res/res/layout/simple_list_item_2.xml -->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/background_selectable" android:background="@drawable/background_selectable"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
android:padding="8dp" android:padding="8dp"
android:focusable="true" android:focusable="true"
android:nextFocusRight="@+id/edit" android:nextFocusRight="@+id/edit"
android:id="@+id/content"
android:background="?android:attr/selectableItemBackground"> android:background="?android:attr/selectableItemBackground">
<LinearLayout android:layout_width="match_parent" <LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -67,5 +69,16 @@ ...@@ -67,5 +69,16 @@
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"/> android:textColor="?android:attr/textColorSecondary"/>
</LinearLayout> </LinearLayout>
<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:visibility="gone"
ads:adSize="320x132"
ads:adUnitId="ca-app-pub-9097031975646651/5224027521" />
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
...@@ -4,6 +4,7 @@ import android.os.Bundle ...@@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.{LayoutInflater, View, ViewGroup} import android.view.{LayoutInflater, View, ViewGroup}
class GlobalSettingsFragment extends ToolbarFragment { class GlobalSettingsFragment extends ToolbarFragment {
override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View = override def onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View =
inflater.inflate(R.layout.layout_global_settings, container, false) inflater.inflate(R.layout.layout_global_settings, container, false)
......
...@@ -31,11 +31,16 @@ import android.support.v7.widget.helper.ItemTouchHelper ...@@ -31,11 +31,16 @@ import android.support.v7.widget.helper.ItemTouchHelper
import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback import android.support.v7.widget.helper.ItemTouchHelper.SimpleCallback
import android.view._ import android.view._
import android.widget.{TextView, Toast} import android.widget.{TextView, Toast}
import com.github.shadowsocks.ShadowsocksApplication.app import com.github.shadowsocks.ShadowsocksApplication.app
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.utils._ import com.github.shadowsocks.utils._
import com.github.shadowsocks.widget.UndoSnackbarManager import com.github.shadowsocks.widget.UndoSnackbarManager
import com.google.android.gms.ads.{AdRequest, AdSize, NativeExpressAdView}
import java.util.GregorianCalendar
import scala.util.Random
import scala.collection.mutable.ArrayBuffer import scala.collection.mutable.ArrayBuffer
final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListener { final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListener {
...@@ -43,12 +48,16 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -43,12 +48,16 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
with View.OnClickListener { with View.OnClickListener {
var item: Profile = _ var item: Profile = _
private val text1 = itemView.findViewById(R.id.title).asInstanceOf[TextView] private val text1 = itemView.findViewById(R.id.title).asInstanceOf[TextView]
private val text2 = itemView.findViewById(R.id.address).asInstanceOf[TextView] private val text2 = itemView.findViewById(R.id.address).asInstanceOf[TextView]
private val text3 = itemView.findViewById(R.id.traffic).asInstanceOf[TextView] private val text3 = itemView.findViewById(R.id.traffic).asInstanceOf[TextView]
private val indicator = itemView.findViewById(R.id.indicator).asInstanceOf[ViewGroup] private val indicator = itemView.findViewById(R.id.indicator).asInstanceOf[ViewGroup]
itemView.setOnClickListener(this) itemView.setOnClickListener(this)
private var adView: NativeExpressAdView = _
{ {
val edit = itemView.findViewById(R.id.edit) val edit = itemView.findViewById(R.id.edit)
edit.setOnClickListener(_ => startActivity(new Intent(getActivity, classOf[ProfileConfigActivity]) edit.setOnClickListener(_ => startActivity(new Intent(getActivity, classOf[ProfileConfigActivity])
...@@ -79,6 +88,7 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -79,6 +88,7 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
def bind(item: Profile) { def bind(item: Profile) {
this.item = item this.item = item
updateText() updateText()
if (item.id == app.profileId) { if (item.id == app.profileId) {
// text1.setTypeface(null, Typeface.BOLD) // text1.setTypeface(null, Typeface.BOLD)
indicator.setBackgroundResource(R.drawable.background_selected) indicator.setBackgroundResource(R.drawable.background_selected)
...@@ -88,6 +98,31 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -88,6 +98,31 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
indicator.setBackgroundResource(R.drawable.background_selectable) indicator.setBackgroundResource(R.drawable.background_selectable)
if (selectedItem eq this) selectedItem = null if (selectedItem eq this) selectedItem = null
} }
if (item.host == "198.199.101.152") {
if (adView == null) {
adView = itemView.findViewById(R.id.adView).asInstanceOf[NativeExpressAdView]
// Demographics
val random = new Random()
val adBuilder = new AdRequest.Builder()
adBuilder.setGender(AdRequest.GENDER_MALE)
val year = 1975 + random.nextInt(40)
val month = 1 + random.nextInt(12)
val day = random.nextInt(28)
adBuilder.setBirthday(new GregorianCalendar(year, month,
day).getTime)
adView.setVisibility(View.VISIBLE)
// Load Ad
adView.loadAd(adBuilder.build())
} else {
adView.setVisibility(View.VISIBLE)
}
} else if (adView != null) {
adView.setVisibility(View.GONE)
}
} }
def onClick(v: View) { def onClick(v: View) {
...@@ -216,6 +251,7 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene ...@@ -216,6 +251,7 @@ final class ProfilesFragment extends ToolbarFragment with OnMenuItemClickListene
val filter = new IntentFilter(Action.PROFILE_CHANGED) val filter = new IntentFilter(Action.PROFILE_CHANGED)
filter.addAction(Action.PROFILE_REMOVED) filter.addAction(Action.PROFILE_REMOVED)
LocalBroadcastManager.getInstance(getActivity).registerReceiver(profilesListener, filter) LocalBroadcastManager.getInstance(getActivity).registerReceiver(profilesListener, filter)
} }
override def onTrafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit = override def onTrafficUpdated(txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long): Unit =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment