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

waiting view 增加 topPageView参数

上级 1bd91505
...@@ -57,17 +57,19 @@ export class WaitingView{ ...@@ -57,17 +57,19 @@ export class WaitingView{
private loadingHeight = 0 private loadingHeight = 0
private LoadingIcon: string = "" private LoadingIcon: string = ""
private mBitmap: Bitmap | null = null; private mBitmap: Bitmap | null = null;
private mpopWindow?: PopupWindow = null private mpopWindow?: PopupWindow = null
private currentHandler: Handler private currentHandler: Handler
private hostView:View | null = null
//{"back":"transmit","height":"112px","loading":{"display":"block","height":"55px","icon":"__uniapperror.png","jSONArray":false},"padding":"10px","size":"16px","width":"140px"} //{"back":"transmit","height":"112px","loading":{"display":"block","height":"55px","icon":"__uniapperror.png","jSONArray":false},"padding":"10px","size":"16px","width":"140px"}
constructor(context?: Activity, style: UTSJSONObject) { constructor(context?: Activity, style: UTSJSONObject,view:View) {
this.context = context; this.context = context;
this.style = style.toJSONObject() as JSONObject this.style = style.toJSONObject() as JSONObject
this.screenWidth = context?.getResources()?.getDisplayMetrics()!.widthPixels this.screenWidth = context?.getResources()?.getDisplayMetrics()!.widthPixels
...@@ -79,7 +81,8 @@ export class WaitingView{ ...@@ -79,7 +81,8 @@ export class WaitingView{
this.textView = this.waitingView.findViewById<TextView>(R.id.dcloud_tv_loading) this.textView = this.waitingView.findViewById<TextView>(R.id.dcloud_tv_loading)
this.seaparatorView = this.waitingView.findViewById<View>(R.id.dcloud_view_seaparator) this.seaparatorView = this.waitingView.findViewById<View>(R.id.dcloud_view_seaparator)
this.mImageView = this.waitingView.findViewById<ImageView>(R.id.dcloud_iv_loading) this.mImageView = this.waitingView.findViewById<ImageView>(R.id.dcloud_iv_loading)
this.hostView = view
this.textView.setMaxLines(2) this.textView.setMaxLines(2)
this.handlerArguments() this.handlerArguments()
...@@ -92,7 +95,7 @@ export class WaitingView{ ...@@ -92,7 +95,7 @@ export class WaitingView{
this.currentHandler = new Handler(Looper.getMainLooper()) this.currentHandler = new Handler(Looper.getMainLooper())
this.initView() this.initView()
this.makeBitmap() this.makeBitmap()
} }
handlerArguments() { handlerArguments() {
...@@ -133,7 +136,7 @@ export class WaitingView{ ...@@ -133,7 +136,7 @@ export class WaitingView{
this.textView.setGravity(Gravity.CENTER) this.textView.setGravity(Gravity.CENTER)
this.textView.setText(this.title) this.textView.setText(this.title)
this.textView.setTextSize(0, (16 * this.density).toFloat()) this.textView.setTextSize(0, (16 * this.density).toFloat())
if(this.title.length < 1){ if(this.title.length < 1){
// 没有文本需要展示 // 没有文本需要展示
this.textView.setVisibility(View.GONE) this.textView.setVisibility(View.GONE)
...@@ -166,8 +169,8 @@ export class WaitingView{ ...@@ -166,8 +169,8 @@ export class WaitingView{
} }
return this.context!.dispatchTouchEvent(ev) return this.context!.dispatchTouchEvent(ev)
} }
showWaiting() { showWaiting() {
if(this.context != null && !this.context!.isFinishing()){ if(this.context != null && !this.context!.isFinishing()){
let width = -2; let width = -2;
...@@ -179,7 +182,7 @@ export class WaitingView{ ...@@ -179,7 +182,7 @@ export class WaitingView{
} }
let mpop = new PopupWindow(this.waitingView, width.toInt(), height.toInt(), this.mask) let mpop = new PopupWindow(this.waitingView, width.toInt(), height.toInt(), this.mask)
this.mpopWindow = mpop this.mpopWindow = mpop
mpop.showAtLocation((this.context?.findViewById<ViewGroup>(android.R.id.content))?.getChildAt(0), Gravity.CENTER, 0, 0) mpop.showAtLocation(hostView, Gravity.CENTER, 0, 0)
mpop.setOutsideTouchable(true) mpop.setOutsideTouchable(true)
mpop.setOnDismissListener(new WaitingDismissListener()) mpop.setOnDismissListener(new WaitingDismissListener())
mpop.setTouchInterceptor(new TouchInterceptorListener(this.mask)) mpop.setTouchInterceptor(new TouchInterceptorListener(this.mask))
...@@ -315,4 +318,4 @@ class TouchInterceptorListener implements View.OnTouchListener { ...@@ -315,4 +318,4 @@ class TouchInterceptorListener implements View.OnTouchListener {
override onTouch(v: View, event: MotionEvent): boolean { override onTouch(v: View, event: MotionEvent): boolean {
return this.interceptor return this.interceptor
} }
} }
\ No newline at end of file
...@@ -31,7 +31,7 @@ let toastType : string | null = null ...@@ -31,7 +31,7 @@ let toastType : string | null = null
export function showToastImpl(style : ShowToastOptions) { export function showToastImpl(style : ShowToastOptions) {
makeToast(style, 'toast', 'showToast') makeToast(style, 'toast', 'showToast')
} }
export function hideToastImpl() { export function hideToastImpl() {
...@@ -108,33 +108,33 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string) ...@@ -108,33 +108,33 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string)
options["width"] = "140" options["width"] = "140"
options["height"] = "112" options["height"] = "112"
// #ifndef UNI-APP-X // #ifndef UNI-APP-X
/** /**
* uni-app * uni-app
*/ */
const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options,UTSAndroid.getTopPageView())
toast = alert toast = alert
alert?.showWaiting(); alert?.showWaiting();
UTSAndroid.onAppActivityDestroy(function(){ UTSAndroid.onAppActivityDestroy(function(){
toast?.close() toast?.close()
toast = null toast = null
}) })
// #endif // #endif
// #ifdef UNI-APP-X // #ifdef UNI-APP-X
/** /**
* uni-app x * uni-app x
* 需要特殊处理生命周期 * 需要特殊处理生命周期
*/ */
const pages = getCurrentPages(); const pages = getCurrentPages();
if (pages.length > 0) { if (pages.length > 0) {
const page = pages[pages.length - 1].vm! const page = pages[pages.length - 1].vm!
const instance = page.$ const instance = page.$
if (page.$isReady) { if (page.$isReady) {
const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options,UTSAndroid.getTopPageView())
toast = alert toast = alert
alert?.showWaiting(); alert?.showWaiting();
} else { } else {
...@@ -142,24 +142,24 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string) ...@@ -142,24 +142,24 @@ function makeLoading(style : ShowLoadingOptions, type : string, errMsg : string)
onReady(() => { onReady(() => {
if(onReadyToast.containsKey(page)){ if(onReadyToast.containsKey(page)){
options = onReadyToast.get(page) as UTSJSONObject; options = onReadyToast.get(page) as UTSJSONObject;
const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options,UTSAndroid.getTopPageView())
toast = alert toast = alert
alert?.showWaiting(); alert?.showWaiting();
onReadyToast.remove(page) onReadyToast.remove(page)
} }
}, instance) }, instance)
} }
onUnload(() => { onUnload(() => {
toast?.close() toast?.close()
toast = null toast = null
}, instance) }, instance)
} }
// #endif // #endif
const res : ShowLoadingSuccess = { const res : ShowLoadingSuccess = {
} }
style.success?.(res) style.success?.(res)
...@@ -178,7 +178,7 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { ...@@ -178,7 +178,7 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) {
style.complete?.(res) style.complete?.(res)
} else { } else {
toastType = type toastType = type
if (["top", "center", "bottom"].indexOf(style.position) >= 0) { if (["top", "center", "bottom"].indexOf(style.position) >= 0) {
androidToast = Toast.makeText(UTSAndroid.getAppContext(), style.title, Toast.LENGTH_SHORT); androidToast = Toast.makeText(UTSAndroid.getAppContext(), style.title, Toast.LENGTH_SHORT);
...@@ -200,7 +200,7 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { ...@@ -200,7 +200,7 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) {
androidToast!.show() androidToast!.show()
const res : ShowToastSuccess = { const res : ShowToastSuccess = {
} }
style.success?.(res) style.success?.(res)
style.complete?.(res) style.complete?.(res)
} else { } else {
...@@ -240,8 +240,8 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { ...@@ -240,8 +240,8 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) {
} }
} }
// #ifndef UNI-APP-X // #ifndef UNI-APP-X
/** /**
* uni-app * uni-app
...@@ -249,17 +249,17 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { ...@@ -249,17 +249,17 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) {
const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options)
toast = alert toast = alert
alert?.showWaiting(); alert?.showWaiting();
UTSAndroid.onAppActivityDestroy(function(){ UTSAndroid.onAppActivityDestroy(function(){
toast?.close() toast?.close()
toast = null toast = null
}) })
// #endif // #endif
// #ifdef UNI-APP-X // #ifdef UNI-APP-X
/** /**
* uni-app x * uni-app x
* 需要特殊处理生命周期 * 需要特殊处理生命周期
*/ */
const pages = getCurrentPages(); const pages = getCurrentPages();
if (pages.length > 0) { if (pages.length > 0) {
...@@ -274,24 +274,24 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { ...@@ -274,24 +274,24 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) {
onReady(() => { onReady(() => {
if(onReadyToast.containsKey(page)){ if(onReadyToast.containsKey(page)){
options = onReadyToast.get(page) as UTSJSONObject; options = onReadyToast.get(page) as UTSJSONObject;
const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options) const alert = new WaitingView(UTSAndroid.getTopPageActivity(), options)
toast = alert toast = alert
alert?.showWaiting(); alert?.showWaiting();
onReadyToast.remove(page) onReadyToast.remove(page)
} }
}, instance) }, instance)
} }
onUnload(() => { onUnload(() => {
toast?.close() toast?.close()
toast = null toast = null
}, instance) }, instance)
} }
// #endif // #endif
let duration : number | null = style.duration let duration : number | null = style.duration
if (duration == null || duration <= 0) { if (duration == null || duration <= 0) {
duration = 1500 duration = 1500
...@@ -301,10 +301,10 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) { ...@@ -301,10 +301,10 @@ function makeToast(style : ShowToastOptions, type : string, errMsg : string) {
toast?.close() toast?.close()
}, duration) }, duration)
} }
const res : ShowToastSuccess = { const res : ShowToastSuccess = {
} }
style.success?.(res) style.success?.(res)
style.complete?.(res) style.complete?.(res)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册