From a9489aea0b0aa87a46fe12c7b486da48ac870e9f Mon Sep 17 00:00:00 2001 From: duqingquan Date: Wed, 9 Nov 2022 19:47:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E9=98=B6=E7=A4=BA=E4=BE=8B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/advance/advance.vue | 7 ++ .../uts-advance/utssdk/app-android/index.uts | 64 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/pages/advance/advance.vue b/pages/advance/advance.vue index ab9afb6..693c110 100644 --- a/pages/advance/advance.vue +++ b/pages/advance/advance.vue @@ -39,6 +39,7 @@ + @@ -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(); diff --git a/uni_modules/uts-advance/utssdk/app-android/index.uts b/uni_modules/uts-advance/utssdk/app-android/index.uts index 8047b55..394bcbf 100644 --- a/uni_modules/uts-advance/utssdk/app-android/index.uts +++ b/uni_modules/uts-advance/utssdk/app-android/index.uts @@ -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) + +} + -- GitLab