index.uts 994 字节
Newer Older
打打卡夫卡's avatar
打打卡夫卡 已提交
1 2 3

import XToast from "com.hjq.xtoast.XToast";
import R from "io.dcloud.uni_modules.uts_toast.R";
杜庆泉's avatar
杜庆泉 已提交
4
import Runnable from 'java.lang.Runnable';
5 6
import Class from 'java.lang.Class';
import Exception from 'java.lang.Exception';
打打卡夫卡's avatar
打打卡夫卡 已提交
7

杜庆泉's avatar
杜庆泉 已提交
8 9 10 11
class UIRunnable extends Runnable {

    override run():void {
		
12
	
13
       new XToast<XToast<unknown>>(UTSAndroid.getUniActivity())
杜庆泉's avatar
杜庆泉 已提交
14 15 16 17 18 19 20 21 22
       				.setDuration(1000)
       				.setContentView(R.layout.window_hint)
       				.setImageDrawable(android.R.id.icon,  android.R.mipmap.sym_def_app_icon)
       				.setText(android.R.id.message, "一秒后自动消失")
       				.show()

    }
};

23 24 25 26 27 28 29 30
export function showToast():boolean{
	let hasXToastIntegration =  true
	try{
		let xToastClass = Class.forName("com.hjq.xtoast.XToast")
		console.log(xToastClass)
	}catch(e:Exception){
		hasXToastIntegration = false;
	}
打打卡夫卡's avatar
打打卡夫卡 已提交
31
	
32 33 34 35
	if(!hasXToastIntegration){
		return false;
	}

杜庆泉's avatar
杜庆泉 已提交
36
	let toastRunable = new UIRunnable();
37
	UTSAndroid.getUniActivity()!.runOnUiThread(toastRunable)
38
	return true
打打卡夫卡's avatar
打打卡夫卡 已提交
39
}