Example #1
0
 protected override void OnCreate(Bundle bundle)
 {
     base.OnCreate (bundle);
     if (bundle == null)
     {
         SetContentView (Resource.Layout.BattlefieldActivityLayout);
         bf = new Battlefield ();
         uiThread = new Runnable (new Action (delegate {
             while(true)
             {
                 RunOnUiThread (drawThread);
                 Thread.Sleep(500);
             }
         }));
         bitmapThread = new Runnable (new Action (delegate {
             while(true)
             {
                 bf.Draw();
                 Thread.Sleep(500);
             }
             //ImageView iv = FindViewById<ImageView> (Resource.Id.imageViewBattlefield);
             //iv.Invalidate();
         }));
         drawThread = new Runnable (new Action (delegate {
             //bf.Draw();
             ImageView iv = FindViewById<ImageView> (Resource.Id.imageViewBattlefield);
             iv.Invalidate();
         }));
     }
 }
Example #2
0
        public void ShowActionSheet()
        {
            #region ActinSheet Items
            List<ActionSheetArgs> items = new List<ActionSheetArgs>();

            var alipayItem = new ActionSheetArgs("支付宝");
            alipayItem.OnClick += () =>
            {
                if (!AlipayHelper.CheckConfig())
                {
                    Toast.MakeText(ApplicationContext,
                        "系统异常.",
                        ToastLength.Long);
                    Log.Error(Tag, "Aplipay Config Exception ");
                    return;
                }
                string payInfo = AlipayHelper.GetPayInfo();
                // 完整的符合支付宝参数规范的订单信息
                Runnable payRunnable = new Runnable(() =>
                {
                    PayTask alipay = new PayTask(this);
                    // 调用支付接口,获取支付结果
                    string result = alipay.Pay(payInfo);

                    Message msg = new Message
                    {
                        What = (int)MsgWhat.AlipayPayFlag,
                        Obj = result
                    };
                    _handler.SendMessage(msg);
                });

                // 必须异步调用
                Thread payThread = new Thread(payRunnable);
                payThread.Start();
            };
            items.Add(alipayItem);
            var weixinItem = new ActionSheetArgs("微信");
            weixinItem.OnClick += () =>
            {
                Runnable wxpayRunnable = new Runnable(() =>
                {
                    _weixinpayHelper = new WeixinpayHelper(this);
                    _weixinpayHelper.Execute();
                });

                // 必须异步调用
                Thread payThread = new Thread(wxpayRunnable);
                payThread.Start();

            };
            items.Add(weixinItem);

            #endregion
            var menuView = new ActionSheet(this);
            menuView.SetCancelButtonTitle("取消");// before add items
            menuView.Items = items;
            menuView.CancelableOnTouchOutside = true;
            menuView.ShowMenu();
        }
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState)
        {
            View rootView = inflater.Inflate(Resource.Layout.user_detail, container, false);

            if (_user != null) {
                ((TextView)rootView.FindViewById (Resource.Id.user_name)).Text = $"{_user.FirstName} {_user.LastName}";
                ((TextView)rootView.FindViewById (Resource.Id.mail_header)).Text = $"[Email]";
                ((TextView)rootView.FindViewById (Resource.Id.user_mail)).Text = _user.Email;
                ((TextView)rootView.FindViewById (Resource.Id.phone_header)).Text = $"[Telefon]";
                ((TextView)rootView.FindViewById (Resource.Id.user_phone)).Text = _user.Phone;
                ((TextView)rootView.FindViewById (Resource.Id.cell_header)).Text = $"[Mobil]";
                ((TextView)rootView.FindViewById (Resource.Id.user_cell)).Text = _user.Cell;

                var imageView = (ImageView)rootView.FindViewById (Resource.Id.user_image);

                Handler handler = new Handler (Context.MainLooper);
                Task.Run (() => {
                    var imageBitmap = ((ImageService)ServiceLocator.Current.GetInstance<ImageService>()).GetUserPicture(_user);
                    Runnable runnable = new Runnable (() => {
                        imageView.SetImageBitmap (imageBitmap);
                    });
                    handler.Post (runnable);
                });
            }
            return rootView;
        }
Example #4
0
 public void Invoke(Action action)
 {
     //Another method
     //http://stackoverflow.com/questions/11123621/running-code-in-main-thread-from-another-thread
     var l = Android.OS.Looper.MainLooper; //Previously Context.GetMainLooper()
     Handler mainHandler = new Handler(l);
     Runnable myRunnable = new Runnable(action);
     mainHandler.Post(myRunnable);
 }
Example #5
0
        private static void Check(string Token, bool CheckType, string card)
        {
            Handler handler = new Handler();

            run = new Java.Lang.Runnable(() =>
            {
                HttpApi.CheckAsync(mResult, Token, CheckType, mac.GetMac(), card);
                handler.PostDelayed(run, 1000 * 20);
            });
            handler.Post(run);
        }
Example #6
0
        public static ICharSequence Parse(
                Context context,
                List<IconFontDescriptorWrapper> iconFontDescriptors,
                string text,
                 TextView target)
        {
            context = context.ApplicationContext;

            // Analyse the text and replace {} blocks with the appropriate character
            // Retain all transformations in the accumulator
            SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(text);
            RecursivePrepareSpannableIndexes(context,
                text, spannableBuilder,
                iconFontDescriptors, 0);
            bool isAnimated = HasAnimatedSpans(spannableBuilder);

            if (isAnimated)
            {
                if (target == null)
                    throw new IllegalArgumentException("You can't use \"spin\" without providing the target TextView.");
                if (!(target is IHasOnViewAttachListener))
                    throw new IllegalArgumentException(target.GetType().Name + " does not implement " +
                            "HasOnViewAttachListener. Please use IconTextView, IconButton or IconToggleButton.");

                bool isAttached = false;
                var listener = new OnViewAttachListener();
                listener.Attach += (s, e) =>
                {
                    isAttached = true;

                    Runnable runnable = null;
                    runnable = new Runnable(() =>
                    {
                        if (isAttached)
                        {
                            target.Invalidate();
                            ViewCompat.PostOnAnimation(target, runnable);
                        }
                    });

                    ViewCompat.PostOnAnimation(target, runnable);
                };

                listener.Detach += (s, e) => isAttached = false;

                ((IHasOnViewAttachListener)target).SetOnViewAttachListener(listener);
            }
            else
            {
                (target as IHasOnViewAttachListener)?.SetOnViewAttachListener(null);
            }

            return spannableBuilder;
        }
        public void ShowToast(string text, bool IsLengthShort = false)
        {
            Handler mainHandler = new Handler(Looper.MainLooper);

            Java.Lang.Runnable runnableToast = new Java.Lang.Runnable(() =>
            {
                var duration = IsLengthShort ? ToastLength.Short : ToastLength.Long;
                Toast.MakeText(this, text, duration).Show();
            });

            mainHandler.Post(runnableToast);
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            show = (TextView)FindViewById(Resource.Id.editText_prepay_id);
            req = new PayReq();
            sb = new System.Text.StringBuilder();
            msgApi = WXAPIFactory.CreateWXAPI(this, null);
            msgApi.RegisterApp(Constants.APP_ID);
            //生成prepay_id
            Button payBtn = FindViewById<Button>(Resource.Id.unifiedorder_btn);

            Dictionary<string, string> xml = new Dictionary<string, string>();

            payBtn.Click += (o, e) => {
                ProgressDialog dialog = ProgressDialog.Show(this, "abc".ToString(), "def");

                IRunnable payRunnable = new Runnable(() => {
                    string url = string.Format("https://api.mch.weixin.qq.com/pay/unifiedorder");
                    string entity = genProductArgs();

                    byte[] buf = Util.httpPost(url, entity);

                    string content = Encoding.Default.GetString(buf);

                    xml = decodeXml(content);
                });

                AsyncTask.Execute(payRunnable);

                if (dialog != null)
                {
                    dialog.Dismiss();
                }
                sb.Append("prepay_id\n" + resultunifiedorder["prepay_id"] + "\n\n");
                show.Text = sb.ToString();
            };

    		Button appayBtn = FindViewById<Button>(Resource.Id.appay_btn);
            appayBtn.Click += (o, e) => {
                sendPayReq();
            };
            //生成签名参数
            Button appay_pre_btn = FindViewById<Button>(Resource.Id.appay_pre_btn);
            appay_pre_btn.Click += (o, e) => {
                genPayReq();
            };
        }
Example #9
0
 public Enemy(int x, int y, int sizeShape, Paint paint, Direction current_direction)
     : base(x,y,sizeShape,paint)
 {
     this.current_direction = current_direction;
     moveThread = new Runnable (new Action (delegate {
         while(true)
         {
             SetLocation (5, 5, current_direction);
             CheckBounds ();
             //Shape.Draw (Battlefield.Draw_canvas);
             Thread.Sleep(500);
         }
     }));
 }
Example #10
0
        public void Execute()
        {
            var checkRunnable = new Runnable(() =>
            {

                const string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
                string entity = GenProductArgs();
                var buf = Util.httpPost(url, entity);

                string content = Encoding.Default.GetString(buf);
                _resultunifiedorder = DecodeXml(content);
                VoidPayWindow(content);
            });

            var checkThread = new Thread(checkRunnable);
            checkThread.Start();
        }
Example #11
0
    public MediaPlayerService()
    {
        PlayingHandler = new Handler(Looper.MainLooper);

        // Create a runnable, restarting itself if the status still is "playing"
        PlayingHandlerRunnable = new Java.Lang.Runnable(() => {
            OnPlaying(EventArgs.Empty);

            if (MediaPlayerState == PlaybackStateCode.Playing)
            {
                PlayingHandler.PostDelayed(PlayingHandlerRunnable, 250);
            }
        });

        // On Status changed to PLAYING, start raising the Playing event
        StatusChanged += (object sender, EventArgs e) => {
            if (MediaPlayerState == PlaybackStateCode.Playing)
            {
                PlayingHandler.PostDelayed(PlayingHandlerRunnable, 0);
            }
        };
    }
        public UnderlinePageIndicator(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            if (IsInEditMode) return;

            var res = Resources;

            var defaultFades = res.GetBoolean(Resource.Boolean.default_underline_indicator_fades);
            var defaultFadeDelay = res.GetInteger(Resource.Integer.default_underline_indicator_fade_delay);
            var defaultFadeLength = res.GetInteger(Resource.Integer.default_underline_indicator_fade_length);
            var defaultSelectedColor = res.GetColor(Resource.Color.default_underline_indicator_selected_color);

            var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.UnderlinePageIndicator, defStyle, 0);

            Fades = a.GetBoolean(Resource.Styleable.UnderlinePageIndicator_fades, defaultFades);
            SelectedColor = a.GetColor(Resource.Styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor);
            FadeDelay = a.GetInteger(Resource.Styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay);
            FadeLength = a.GetInteger(Resource.Styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength);

            var background = a.GetDrawable(Resource.Styleable.UnderlinePageIndicator_android_background);
            if(null != background)
                Background = background;

            a.Recycle();

            var configuration = ViewConfiguration.Get(context);
            _touchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration);

            _fadeRunnable = new Runnable(() =>
            {
                if (!_fades) return;

                var alpha = Math.Max(_paint.Alpha - _fadeBy, 0);
                _paint.Alpha = alpha;
                Invalidate();
                if (alpha > 0)
                    PostDelayed(_fadeRunnable, FadeFrameMs);
            });
        }
        private void AnimateToIcon(int position)
        {
            var iconView = _iconsLayout.GetChildAt(position);
            if (_iconSelector != null)
                RemoveCallbacks(_iconSelector);

            _iconSelector = new Runnable(() =>
            {
                var scrollPos = iconView.Left - (Width - iconView.Width) / 2;
                SmoothScrollTo(scrollPos, 0);
                _iconSelector = null;
            });
            Post(_iconSelector);
        }
        /**
	 * check whether the device has authentication alipay account.
	 * 查询终端设备是否存在支付宝认证账户
	 * 
	 */
        public void check(object o, EventArgs e)
        {
            Runnable checkRunnable = new Runnable(()=> {
                PayTask payTask = new PayTask(this);
                // 调用查询接口,获取查询结果
                bool isExist = payTask.CheckAccountIfExist();

                Message msg = new Message();
                msg.What = SDK_CHECK_FLAG;
                msg.Obj = isExist;
                mHandler.SendMessage(msg);
            });

            Thread checkThread = new Thread(checkRunnable);
            checkThread.Start();

        }
        public void pay(object o, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(PARTNER) || string.IsNullOrWhiteSpace(RSA_PRIVATE)
                    || string.IsNullOrWhiteSpace(SELLER))
            {
                new AlertDialog.Builder(this)
                        .SetTitle("警告")
                        .SetMessage("需要配置PARTNER | RSA_PRIVATE| SELLER")
                        .SetPositiveButton("确定", (dialoginterface, i) => { Finish(); }

                                ).Show();
                return;
            }
            // 订单
            string orderInfo = GetOrderInfo("测试的商品", "该测试商品的详细描述", "0.01");

            // 对订单做RSA 签名
            string sign = Sign(orderInfo);
            try
            {
                // 仅需对sign 做URL编码
                sign = Java.Net.URLEncoder.Encode(sign, "UTF-8");
            }
            catch (UnsupportedEncodingException ex)
            {
                ex.PrintStackTrace();
            }
            finally
            {
                string payInfo = orderInfo + "&sign=\"" + sign + "\"&"
                                + GetSignType();
                // 完整的符合支付宝参数规范的订单信息
                Runnable payRunnable = new Runnable(()=> {
                    PayTask alipay = new PayTask(this);
                    // 调用支付接口,获取支付结果
                    string result = alipay.Pay(payInfo);

                    Message msg = new Message();
                    msg.What = SDK_PAY_FLAG;
                    msg.Obj = result;
                    mHandler.SendMessage(msg);
                });
                
                // 必须异步调用
                Thread payThread = new Thread(payRunnable);
                payThread.Start();
            }


        }
            public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
            {
                ((ViewHolder)holder).mItem = _users [position];
                ((ViewHolder)holder).mIdView.SetImageBitmap (null);

                //	set user image async
                Handler handler = new Handler (_context.MainLooper);
                Task.Run (() => {
                    var imageBitmap = ((ImageService)ServiceLocator.Current.GetInstance<ImageService> ()).GetUserThumbnail (((ViewHolder)holder).mItem);
                    Runnable runnable = new Runnable (() => {
                        ((ViewHolder)holder).mIdView.SetImageBitmap (imageBitmap);
                    });
                    handler.Post (runnable);
                });

                ((ViewHolder)holder).mContentView.Text = $"{(_users[position]).FirstName} {(_users[position]).LastName}";
                ((ViewHolder)holder).mView.SetOnClickListener (new ClickListener ((ViewHolder)holder, _fragmentManager));
            }
        public virtual void HideAndStop()
        {
            Hide();

            var r = new Runnable(Start);

            _handler.PostDelayed(r, ShowSpeed);
        }
        public virtual void ShowAndPlay()
        {
            Show();


            var r = new Runnable(Start);

            _handler.PostDelayed(r, ShowSpeed);
        }
		public GlobalLayoutListener(View view, Runnable runnable)
		{
			_view = view;
			_runnable = runnable;
		}
    /**
     * Add an OnGlobalLayoutListener for the view.
     * This is just a convenience method for using {@code ViewTreeObserver.OnGlobalLayoutListener()}.
     * This also handles removing listener when onGlobalLayout is called.
     *
     * @param view     the target view to add global layout listener
     * @param runnable runnable to be executed after the view is laid out
     */
    public static void AddOnGlobalLayoutListener(View view, Runnable runnable) {
	    view.ViewTreeObserver.AddOnGlobalLayoutListener(new GlobalLayoutListener(view, runnable));
    }
Example #21
0
        private void TecentPayPay(object sender, EventArgs args)
        {
            _msgApi.RegisterApp(Constants.AppId);


            var checkRunnable = new Runnable(() =>
            {


                string url = string.Format("https://api.mch.weixin.qq.com/pay/unifiedorder");
                string entity = GenProductArgs();
                var buf = Util.httpPost(url, entity);

                string content = System.Text.Encoding.Default.GetString(buf);
                _resultunifiedorder = DecodeXml(content);
                var msg = new Message
                {
                    What = (int)MsgWhat.TencentValidateFlag,
                    Obj = content
                };
                _handler.SendMessage(msg);
            });

            Java.Lang.Thread checkThread = new Java.Lang.Thread(checkRunnable);
            checkThread.Start();

        }
Example #22
0
 /**
  * Execute code in a separate thread.
  * Use this for blocking and/or cpu intensive operations and thus avoid blocking the UI.
  *
  * @param r The Runner subclass to execute
  */
 protected void execInThread(Runnable r)
 {
     pool.execute(r);
 }
Example #23
0
        /**
         * Execute code in a separate thread.
         * Any exception thrown by the thread will be added to the error list
         * @param r The runner subclass to execute
         */
        protected void SyncInThread(Runnable r)
        {
            //			Runnable task = new Runnable() {
            //				public void run() {
            //					try {
            //						r.run();
            //					} catch(Exception e) {
            //						TLog.e(TAG, e, "Problem syncing in thread");
            //						SendMessage(PARSING_FAILED, ErrorList.createError("System Error", "system", e));
            //					}
            //				}
            //			};

            execInThread(task);
        }
Example #24
0
        private void AlipayPay(object sender, EventArgs args)
        {


            if (!AliPayHelper.CheckConfig())
            {
                Toast.MakeText(ApplicationContext,
                    "系统异常.",
                    ToastLength.Long);
                Log.Error(Tag, "Aplipay Config Exception ");
                return;
            }
            string payInfo = AliPayHelper.GetPayInfo();
            // 完整的符合支付宝参数规范的订单信息
            Runnable payRunnable = new Runnable(() =>
            {
                PayTask alipay = new PayTask(this);
                // 调用支付接口,获取支付结果
                string result = alipay.Pay(payInfo);

                Message msg = new Message
                {
                    What = (int)MsgWhat.AlipayPayFlag,
                    Obj = result
                };
                _handler.SendMessage(msg);
            });

            // 必须异步调用
            Thread payThread = new Thread(payRunnable);
            payThread.Start();
        }
Example #25
0
        public System.Text.StringBuilder build()
        {
            runner = new Runnable() {

            //				public void run() {
            //
            //
            //					bool successful = true;
            //
            //					try {
            //						// Parsing
            //				    	// XML
            //				    	// Get a SAXParser from the SAXPArserFactory
            //				        SAXParserFactory spf = SAXParserFactory.newInstance();
            //
            //				        // trashing the namespaces but keep prefixes (since we don't have the xml header)
            //				        spf.setFeature("http://xml.org/sax/features/namespaces", false);
            //				        spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
            //				        SAXParser sp = spf.newSAXParser();
            //
            //						TLog.v(TAG, "parsing note {0}", subjectName);
            //
            //				        sp.parse(noteContentIs, new NoteContentHandler(noteContent));
            //					} catch (Exception e) {
            //						e.PrintStackTrace();
            //						// TODO handle error in a more granular way
            //						TLog.e(TAG, "There was an error parsing the note {0}", noteContentstring);
            //						successful = false;
            //					}
            //
            //					warnHandler(successful);
            //				}
            };
            System.Threading.Thread thread = new System.Threading.Thread(runner);
            thread.Start();
            return noteContent;
        }