﻿Type=Class
Version=3.8
B4A=true
@EndOfDesignText@
'Class module
Sub Class_Globals
	
End Sub

'有米广告初始化
'AppId:应用的发布ID
'AppSecret应用的发布密钥
'Model:True为测试模式,False为不是测试模式
Public Sub Initialize(AppId As String, AppSecret As String,Model As Boolean)
GetAdManager.RunMethodjo("init",Array(AppId,AppSecret,Model))
GetOffersManager.RunMethodjo("onAppLaunch",Null)
End Sub
'展示积分墙
Public Sub showOffersWall
GetOffersManager.RunMethodjo("showOffersWall",Null)
End Sub
'展示悬浮半屏积分墙
Public Sub showOffersWallDialog
GetOffersManager.RunMethodjo("showOffersWallDialog",Array(GetActivity))
End Sub

'请务必调用积分广告的初始化接口:
Public Sub onAppLaunch
GetOffersManager.RunMethodJO("onAppLaunch",Null)
End Sub
'在应用退出的地方
'Sub Activity_Pause (UserClosed As Boolean) 
'If UserClosed=True Then
'..... 
'End If 
'End Sub
'调用以下代码进行资源回收
Public Sub onAppExit
GetOffersManager.RunMethodjo("onAppExit",Null)
End Sub

'注册积分监听-随时随地获得积分的变动情况
Public Sub registerNotify
GetPointsManager.RunMethodJO("registerNotify",Array(getCallback))
End Sub

'注销积分监听-如果在onCreate注册了，那这里必须得注销
Public Sub unRegisterNotify
GetPointsManager.RunMethodJO("unRegisterNotify",Array(getCallback))
End Sub

'积分查询
Sub queryPoints As Int
Return GetPointsManager.RunMethod("queryPoints",Null)
End Sub
'扣除积分
'amount:积分数量
Sub spendPoints(amount As Int) As Boolean
Return GetPointsManager.RunMethod("spendPoints",Array(amount))
End Sub
'增加积分
'amount:积分数量
Sub awardPoints(amount As Int) As Boolean
Return GetPointsManager.RunMethod("awardPoints",Array(amount))
End Sub
'初始化插屏广告
Public Sub loadSpotAds
GetSpotManager.RunMethodJO("loadSpotAds",Null)
End Sub
'显示插屏广告
Public Sub showSpotAds
GetSpotManager.RunMethodJO("showSpotAds",Array(GetContext))
End Sub
'PointsChangeNotify回调函数
Public Sub getCallback As Object
Dim jo As JavaObject=GetPointsManager
Dim callback As Object = jo.CreateEvent("net.youmi.android.offers.PointsChangeNotify", "PointsChangeNotify", Null)
Return callback 
End Sub
Private Sub GetPointsManager As JavaObject
   Dim jo As JavaObject
   'com.squareup.picasso.Picasso.with(context)
   Return jo.InitializeStatic("net.youmi.android.offers.PointsManager").RunMethod("getInstance", Array(GetContext))
End Sub
Private Sub GetAdManager As JavaObject
   Dim jo As JavaObject
   'com.squareup.picasso.Picasso.with(context)
   Return jo.InitializeStatic("net.youmi.android.AdManager").RunMethod("getInstance", Array(GetContext))
End Sub

Private Sub GetOffersManager As JavaObject
   Dim jo As JavaObject
   Return jo.InitializeStatic("net.youmi.android.offers.OffersManager").RunMethod("getInstance", Array(GetContext))
End Sub

Private Sub GetSpotManager As JavaObject
   Dim jo As JavaObject
   Return jo.InitializeStatic("net.youmi.android.spot.SpotManager").RunMethod("getInstance", Array(GetContext))
End Sub

Private Sub GetActivity As Object
    Dim R  As Reflector
    Return R.GetActivity
End Sub

Private Sub GetContext As JavaObject
   Return GetBA.GetField("context")
End Sub

Private Sub GetBA  As JavaObject
 Dim jo As JavaObject
    Dim cls As String = Me
    If Not(cls.StartsWith("class")) Then
        cls = GetType(Me)
        cls = cls.SubString2(0,cls.LastIndexOf(".")+1) & "main"
    Else
        cls = Me
        cls = cls.SubString("class ".Length)
    End If
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub

Public Sub Callback_Event (MethodName As String, Args() As Object) As Object
   Return Null
End Sub