提交 a9489aea 编写于 作者: 杜庆泉's avatar 杜庆泉

进阶示例增加获取用户输入

上级 fa71d2a8
......@@ -39,6 +39,7 @@
<uni-list-item @tap="testLifecyle" title="activity生命周期监听" :clickable="true" link />
<uni-list-item @tap="gotoDecorView" title="操作DecorView" :clickable="true" link />
<uni-list-item @tap="testInputDialog" title="同步获取用户输入" :clickable="true" />
<uni-list-item @tap="testMetaRead" title="读取meta配置" :clickable="true" />
<uni-list-item @tap="testAssetLoad" title="播放asset音频(需自定义基座)" :clickable="true" />
......@@ -56,6 +57,7 @@
doIntervalTask,
clearIntervalTask,
playAssetAudio,
getUserInput,
getMetaConfig
} from "../../uni_modules/uts-advance";
......@@ -134,6 +136,11 @@
testAssetLoad() {
playAssetAudio();
},
testInputDialog() {
getUserInput(function(res){
console.log(res);
});
},
testMetaRead() {
let ret = getMetaConfig();
......
......@@ -16,6 +16,13 @@ import Activity from "android.app.Activity";
import Bitmap from "android.graphics.Bitmap";
import FileOutputStream from "java.io.FileOutputStream";
import Toast from 'android.widget.Toast';
import AlertDialog from 'android.app.AlertDialog';
import DialogInterface from 'android.content.DialogInterface';
import EditText from 'android.widget.EditText';
import {
onAppActivityDestroy,
onAppActivityPause,
......@@ -143,6 +150,63 @@ export function removeViewToDecorView() {
}
class DialogListener extends DialogInterface.OnClickListener{
inputET:EditText
callback:UTSCallback
constructor(et:EditText,cb:UTSCallback){
super();
this.callback = cb;
this.inputET = et;
}
override onClick(_dialog:DialogInterface,_arg1:Int ):void {
//数据获取
let input = this.inputET.getText().toString()
this.callback(input);
Toast.makeText(getUniActivity(),input,
Toast.LENGTH_LONG).show();
}
}
class DialogUIRunnable extends Runnable {
callback:UTSCallback
constructor(success:UTSCallback){
super();
this.callback = success
}
override run():void {
let et = new EditText(getUniActivity());
et.setText("127.0.0.1");
new AlertDialog.Builder(getUniActivity()).setTitle("请输入IP地址")
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
.setPositiveButton("确定", new DialogListener(et,this.callback))
.setNegativeButton("取消", null).show();
}
};
/**
* 通过对话框同步获取用户输入
*/
export function getUserInput(success: (res: string) => void) {
let uiRunable = new DialogUIRunnable(success);
getUniActivity()!.runOnUiThread(uiRunable)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册