Android Question how to get jar object or get new view by jar?

xiaoyao

Member
Licensed User
Longtime User
Sub GetDimValInt(Cls As String ,dimName As String ) As Int
':Msgbox(GetDimValInt("net.youmi.android.spot.SpotManager","ORIENTATION_PORTRAIT"),"")=0,ORIENTATION_LANDSCAPE=1

'dimName:Constant variable names in the library, Cls: reference package name class name

Dim A As Int
Dim jo As JavaObject
jo.InitializeStatic(Cls)
A= jo.GetField(dimName)
Return A
End Sub

i have a jar file,name is :YoumiSdkpic.jar
if i want to get the value like java:SpotManager.ORIENTATION_PORTRAIT
i can use GetDimValInt("net.youmi.android.spot.SpotManager","ORIENTATION_PORTRAIT"),the value =0
it's a number.
if i want to get a view ,how to do? and it's need to create new view from jar.

java code is:

// 实例化广告条
AdView adView = new AdView(this, AdSize.FIT_SCREEN);

// 获取要嵌入广告条的布局
LinearLayout adLayout=(LinearLayout)findViewById(R.id.adLayout);

// 将广告条加入到布局中
adLayout.addView(adView);

how can i write the code to use this jar? (it's no xml file,only put JAR FILE TO LIB PATH(YoumiSdkpic.jar
),WITH "#AdditionalJar: YoumiSdkpic" IN MAIN ACTIVITY.
 

xiaoyao

Member
Licensed User
Longtime User
how to change this java code to b4a by (JavaObject) and (Reflector)?

private void showBanner() {

// 广告条接口调用(适用于应用)
// 将广告条adView添加到需要展示的layout控件中
// LinearLayout adLayout = (LinearLayout) findViewById(R.id.adLayout);
// AdView adView = new AdView(this, AdSize.FIT_SCREEN);
// adLayout.addView(adView);

// 广告条接口调用(适用于游戏)

// 实例化LayoutParams(重要)
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
// 设置广告条的悬浮位置
layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; // 这里示例为右下角
// 实例化广告条
AdView adView = new AdView(this, AdSize.FIT_SCREEN);
// 调用Activity的addContentView函数

// 监听广告条接口
adView.setAdListener(new AdViewListener() {

@override
public void onSwitchedAd(AdView arg0) {
Log.i("YoumiAdDemo", "广告条切换");
}

@override
public void onReceivedAd(AdView arg0) {
Log.i("YoumiAdDemo", "请求广告成功");

}

@override
public void onFailedToReceivedAd(AdView arg0) {
Log.i("YoumiAdDemo", "请求广告失败");
}
});
this.addContentView(adView, layoutParams);
}
 

Attachments

  • demo.zip
    141.1 KB · Views: 238
Upvote 0

xiaoyao

Member
Licensed User
Longtime User
how to change this java code to b4a ,without lib.(in normally, we need make a java file to a new lib and xml file),i want to direct use JAR , HOW TO DO?IF THE B4A PROJECT NO NEED UI FOR JAR,IT'S EASY.IF THE JAR WITH UI,VIEW ,OR EVENTS,IT'S HARD!
<pre>
package com.youmi.android.addemo;

import net.youmi.android.banner.AdSize;
import net.youmi.android.banner.AdView;
import net.youmi.android.banner.AdViewListener;
import net.youmi.android.spot.SpotDialogListener;
import net.youmi.android.spot.SpotManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.Toast;

public class YoumiNormalAdsDemo extends Activity {

@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ad);

// 初始化接口,应用启动的时候调用,只需要定义一次,因为已经在开屏中初始化,所以此处不用再初始化,如果没有使用开屏,请记得将初始化函数加入。
// 参数:appId, appSecret, 调试模式
// AdManager.getInstance(this).init("85aa56a59eac8b3d",
// "a14006f66f58d5d7", false);

// 插播接口调用
// 开发者可以到开发者后台设置展示频率,需要到开发者后台设置页面(详细信息->业务信息->无积分广告业务->高级设置)
// 自4.03版本增加云控制是否开启防误点功能,需要到开发者后台设置页面(详细信息->业务信息->无积分广告业务->高级设置)

// 加载插播资源
SpotManager.getInstance(this).loadSpotAds();
// 插屏出现动画效果,0:ANIM_NONE为无动画,1:ANIM_SIMPLE为简单动画效果,2:ANIM_ADVANCE为高级动画效果
SpotManager.getInstance(this).setAnimationType(SpotManager.ANIM_ADVANCE);
// 设置插屏动画的横竖屏展示方式,如果设置了横屏,则在有广告资源的情况下会是优先使用横屏图。
SpotManager.getInstance(this).setSpotOrientation(
SpotManager.ORIENTATION_PORTRAIT);
Button spotBtn = (Button) findViewById(R.id.showSpot);
spotBtn.setOnClickListener(new OnClickListener() {
@override
public void onClick(View v) {

// 展示插播广告,可以不调用loadSpot独立使用
SpotManager.getInstance(YoumiNormalAdsDemo.this).showSpotAds(
YoumiNormalAdsDemo.this, new SpotDialogListener() {
@override
public void onShowSuccess() {
Log.i("YoumiAdDemo", "展示成功");
}

@override
public void onShowFailed() {
Log.i("YoumiAdDemo", "展示失败");
}

@override
public void onSpotClosed() {
Log.i("YoumiAdDemo", "展示关闭");
}

}); // //

}
});

Button bannerBtn = (Button) findViewById(R.id.showBanner);
bannerBtn.setOnClickListener(new OnClickListener() {

@override
public void onClick(View v) {
Toast.makeText(YoumiNormalAdsDemo.this, "正在加载banner中,请稍等", Toast.LENGTH_SHORT).show();
showBanner();
}
});

}

private void showBanner() {

// 广告条接口调用(适用于应用)
// 将广告条adView添加到需要展示的layout控件中
// LinearLayout adLayout = (LinearLayout) findViewById(R.id.adLayout);
// AdView adView = new AdView(this, AdSize.FIT_SCREEN);
// adLayout.addView(adView);

// 广告条接口调用(适用于游戏)

// 实例化LayoutParams(重要)
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
// 设置广告条的悬浮位置
layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; // 这里示例为右下角
// 实例化广告条
AdView adView = new AdView(this, AdSize.FIT_SCREEN);
// 调用Activity的addContentView函数

// 监听广告条接口
adView.setAdListener(new AdViewListener() {

@override
public void onSwitchedAd(AdView arg0) {
Log.i("YoumiAdDemo", "广告条切换");
}

@override
public void onReceivedAd(AdView arg0) {
Log.i("YoumiAdDemo", "请求广告成功");

}

@override
public void onFailedToReceivedAd(AdView arg0) {
Log.i("YoumiAdDemo", "请求广告失败");
}
});
this.addContentView(adView, layoutParams);
}

@override
public void onBackPressed() {
// 如果有需要,可以点击后退关闭插播广告。
if (!SpotManager.getInstance(this).disMiss()) {
// 弹出退出窗口,可以使用自定义退屏弹出和回退动画,参照demo,若不使用动画,传入-1
super.onBackPressed();
}
}

@override
protected void onStop() {
// 如果不调用此方法,则按home键的时候会出现图标无法显示的情况。
SpotManager.getInstance(this).onStop();
super.onStop();
}

@override
protected void onDestroy() {
SpotManager.getInstance(this).onDestroy();
super.onDestroy();
}

}
</pre>
 
Last edited:
Upvote 0

xiaoyao

Member
Licensed User
Longtime User
can you help me? i use this code ,but can't show view,no view added
which code in b4a to use "setContentView"?

// 传入需要跳转的activity
SplashView splashView = new SplashView(this, YoumiNormalAdsDemo.class);

// 开屏也可以作为控件加入到界面中。
setContentView(splashView.getSplashView());



Dim VIEW1 As Object
VIEW1=ad.CreateRatingBar("rbar")
Activity.AddView(VIEW1 , 0, 0, Panel1.Width , Panel1.Height )


Public Sub CreateRatingBar (EventName As String) As Object
Dim context As Object = GetBA.GetField("context")
Dim jo As JavaObject
jo.InitializeNewInstance("net.youmi.android.banner.AdView", Array (context))
Dim event As Object = jo.CreateEventFromUI("net.youmi.android.banner.AdViewListener", _
EventName, Null)
jo.RunMethod("setAdListener", Array(event))
Return jo
end sub
 
Upvote 0
Top