示例#1
0
 void enqueueAction(Action action)
 {
     if (serviceConnected)
     {
         mainLooper.Post(action);
     }
     else
     {
         serviceActions.Add(action);
     }
 }
示例#2
0
        public HostedActivityManager(Context context)
        {
            Context        = context;
            serviceActions = new List <Action> ();
            sessionId      = -1;
            mainLooper     = new global::Android.OS.Handler(global::Android.OS.Looper.MainLooper);

            connection = new HostedServiceConnection {
                OnServiceConnectedHandler = (name, service) => {
                    if (browserConnectionCallback == null)
                    {
                        browserConnectionCallback = new BrowserConnectionCallback {
                            Handler = (sessionId, url, extras) => {
                                var evt = UserNavigation;
                                if (evt != null)
                                {
                                    evt(sessionId, url, extras);
                                }
                            }
                        };
                    }

                    //var svcBinder = service as BrowserConnectionServiceBinder;
                    connectionService = IBrowserConnectionServiceStub.AsInterface(service);  //IBrowserConnectionService.Stub.AsInterface (service); // svcBinder.GetSvc (); // IBrowserConnectionService.AsInterface(service);
                    try {
                        if (browserConnectionCallback != null)
                        {
                            connectionService.FinishSetup(browserConnectionCallback);
                        }
                        sessionId = connectionService.NewSession();
                    } catch (global::Android.OS.RemoteException e) {
                        sessionId         = -1;
                        connectionService = null;
                        return;
                    }
                    serviceConnected = true;
                    foreach (var a in serviceActions)
                    {
                        mainLooper.Post(a);
                    }
                    serviceActions.Clear();
                },
                OnServiceDisconnectedHandler = (name) => {
                    serviceConnected = false;

                    if (shouldRebind)
                    {
                        BindService();
                    }
                }
            };
        }
示例#3
0
 public void Execute(Java.Lang.IRunnable r)
 {
     handler.Post(r);
 }