Esempio n. 1
0
        protected override void PlatformShow(string text, int duration)
        {
            var context   = AndroidApplication.Context;
            var duration2 = (AndroidToastLength)duration;

            // https://blog.csdn.net/android157/article/details/80267737
            try
            {
                if (toast == null)
                {
                    toast = AndroidToast.MakeText(context, text, duration2);
                    if (toast == null)
                    {
                        throw new NullReferenceException("toast markeText Fail");
                    }
                }
                else
                {
                    toast.Duration = duration2;
                }
                SetTextAndShow(toast, text);
            }
            catch (JException e)
            {
                Log.Error(TAG, e, "ShowDroidToast Error, text: {0}", text);
                // 解决在子线程中调用Toast的异常情况处理
                Looper.Prepare();
                var _toast = AndroidToast.MakeText(context, text, duration2)
                             ?? throw new NullReferenceException("toast markeText Fail(2)");
                SetTextAndShow(_toast, text);
                Looper.Loop();
            }
Esempio n. 2
0
        //static AndroidToast? toast;
        //static DateTime hideTime;

        //static int GetHideTimeByDuration(int duration, AndroidToastLength duration2)
        //{
        //    if (duration2 == AndroidToastLength.Long)
        //    {
        //        return (int)ToastLength.Long;
        //    }
        //    else if (duration2 == AndroidToastLength.Short)
        //    {
        //        return (int)ToastLength.Short;
        //    }
        //    return duration;
        //}

        protected override void PlatformShow(string text, int duration)
        {
            var context   = XEPlatform.CurrentActivity?.ApplicationContext ?? XEPlatform.AppContext;
            var duration2 = (AndroidToastLength)duration;

            // https://blog.csdn.net/android157/article/details/80267737
            try
            {
                //if (toast == null)
                //{
                var toast = AndroidToast.MakeText(context, text, duration2);
                //if (toast == null) throw new NullReferenceException("toast markeText Fail");
                //}
                //else
                //{
                //    toast.Duration = duration2;
                //}
                SetTextAndShow(toast !, text);
            }
            catch (JException e)
            {
                Log.Error(TAG, e, "ShowDroidToast Error, text: {0}, IsMainThread: {1}", text, IsMainThread);
                // 解决在子线程中调用Toast的异常情况处理
                Looper.Prepare();
                var _toast = AndroidToast.MakeText(context, text, duration2)
                             ?? throw new NullReferenceException("toast markeText Fail(2)");
                SetTextAndShow(_toast, text);
                Looper.Loop();
            }
Esempio n. 3
0
 public static void showCenterToast(Android.Content.Context ctx, string text, Android.Widget.ToastLength duration)
 {
     Android.App.Activity act = (Android.App.Activity)ctx;
     act.RunOnUiThread(() => {
         Android.Widget.Toast toast = Android.Widget.Toast.MakeText(ctx, text, duration);
         toast.SetGravity(Android.Views.GravityFlags.Center, 0, 0);
         toast.Show();
     });
 }
Esempio n. 4
0
 static void SetTextAndShow(AndroidToast t, string text)
 {
     // 某些定制ROM会更改内容文字,例如MIUI,重新设置可强行指定文本
     t.SetText(text);
     //var now = DateTime.Now;
     //if (hideTime == default || hideTime <= now) // 同一时间内多次调用 Show 将会导致无法显示
     //{
     //    hideTime = now.AddMilliseconds(GetHideTimeByDuration(duration, duration2));
     t.Show();
     //}
 }
Esempio n. 5
0
 public void OnLoadmore(IRefreshLayout refreshlayout)
 {
     refreshlayout.Layout.PostDelayed(() => {
         _activity.mAdapter.Loadmore(_activity.loadModels());
         refreshlayout.FinishLoadmore();
         if (_activity.mAdapter.ItemCount > 12)
         {
             Toast.MakeText(_activity.Application, "数据全部加载完毕", ToastLength.Short).Show();
             refreshlayout.SetLoadmoreFinished(true);//将不会再次触发加载更多事件
         }
     }, 2000);
 }
 public void OnLoadmore(IRefreshLayout refreshLayout)
 {
     ((View)refreshLayout).PostDelayed(() => {
         activity.mAdapter.Loadmore(activity.initData);
         refreshLayout.FinishLoadmore();
         if (activity.mAdapter.Count > 60)
         {
             Toast.MakeText(activity.Application, "数据全部加载完毕", ToastLength.Short).Show();
             refreshLayout.SetLoadmoreFinished(true);//将不会再次触发加载更多事件
         }
     }, 2000);
 }
Esempio n. 7
0
 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
 {
     // Check which request we're responding to
     if (requestCode == Tango.TangoIntentActivitycode)
     {
         // Make sure the request was successful
         if (resultCode == Result.Canceled)
         {
             Toast.MakeText(this, motiontrackingcsharp.Resource.String.motiontrackingpermission, Android.Widget.ToastLength.Short).Show();
             Finish();
         }
     }
 }
 public ADFDataSource(Context context)
 {
     mContext = context;
     mTango   = new Tango(context);
     try
     {
         mFullUUIDList = mTango.ListAreaDescriptions();
     }
     catch (TangoErrorException)
     {
         Toast.MakeText(mContext, Resource.String.tango_error, Android.Widget.ToastLength.Short).Show();
     }
     if (mFullUUIDList.Count == 0)
     {
         Toast.MakeText(context, Resource.String.no_adfs_tango_error, Android.Widget.ToastLength.Short).Show();
     }
 }
 public virtual void deleteADFandUpdateList(string uuid)
 {
     try
     {
         mTango.DeleteAreaDescription(uuid);
     }
     catch (TangoErrorException)
     {
         Toast.MakeText(mContext, Resource.String.no_uuid_tango_error, Android.Widget.ToastLength.Short).Show();
     }
     mFullUUIDList.Clear();
     try
     {
         mFullUUIDList = mTango.ListAreaDescriptions();
     }
     catch (TangoErrorException)
     {
         Toast.MakeText(mContext, Resource.String.tango_error, Android.Widget.ToastLength.Short).Show();
     }
 }
        public static void Show(string text, BaseView view = null
                                )
        {
#if __ANDROID__
            if (toast != null)
            {
                toast.Cancel();
            }

            toast = Android.Widget.Toast.MakeText(Xamarin.Forms.Forms.Context, text, Android.Widget.ToastLength.Short);
            toast.Show();
#elif __IOS__
            ToastIOS.Toast.MakeText(text).SetFontSize(12f).Show();
#elif __UWP__
            if (view != null)
            {
                view.Toast(text);
            }
            else
            {
                new Windows.UI.Popups.MessageDialog(text);
            }
#endif
        }
Esempio n. 11
0
 static void SetTextAndShow(AndroidToast t, string text)
 {
     // 某些定制ROM会更改内容文字,例如MIUI,重新设置可强行指定文本
     t.SetText(text);
     t.Show();
 }