protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create and attach the view that is responsible for painting. mView = new PaintView(this); SetContentView(mView); mView.RequestFocus(); // Restore the fading option if we are being thawed from a // previously saved state. Note that we are not currently remembering // the contents of the bitmap. if (bundle != null) { mFading = bundle.GetBoolean("fading", true); mView.mColorIndex = bundle.GetInt("color", 0); } else { mFading = true; mView.mColorIndex = 0; } mHandler = new MyHandler(this); }
public void ReadWrite() { var pp = new Pipeline(); var h1 = new MyHandler { Value = 1 }; var h2 = new MyHandler { Value = 2 }; var h3 = new MyHandler { Value = 3 }; pp.Add(h1); pp.Add(h2); pp.Add(h3); var list = new List <Int32>(); var rs = pp.Read(null, list); Assert.Equal(list, rs); Assert.Equal(1, list[0]); Assert.Equal(2, list[1]); Assert.Equal(3, list[2]); var list2 = new List <Int32>(); var rs2 = pp.Write(null, list2); Assert.Equal(list2, rs2); Assert.Equal(3, list2[0]); Assert.Equal(2, list2[1]); Assert.Equal(1, list2[2]); }
protected void Page_Load(object sender, EventArgs e) { HttpContext contex = Context; MyHandler temp = new MyHandler(); temp.ProcessRequest(context); }
public void SendAsync_NullRequest_ThrowsArgumentNullException() { RemoteInvoke(async() => { var diagnosticListenerObserver = new FakeDiagnosticListenerObserver(null); using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver)) { diagnosticListenerObserver.Enable(); using (MyHandler handler = new MyHandler()) { // Getting the Task first from the .SendAsync() call also tests // that the exception comes from the async Task path. Task t = handler.SendAsync(null); if (PlatformDetection.IsUap) { await Assert.ThrowsAsync <HttpRequestException>(() => t); } else { await Assert.ThrowsAsync <ArgumentNullException>(() => t); } } } diagnosticListenerObserver.Disable(); return(SuccessExitCode); }).Dispose(); }
/// <summary> /// The OnCreate /// </summary> /// <param name="savedInstanceState">The savedInstanceState<see cref="Bundle"/></param> protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Xamarin.Essentials.Platform.Init(this, savedInstanceState); filepath = FindViewById <TextView>(Resource.Id.filePath); // Set our view from the "main" layout resource button = FindViewById <Button>(Resource.Id.filebtn); button.Click += (e, o) => { OnFileSelect(); }; Window.AddFlags(WindowManagerFlags.KeepScreenOn); mHandler = new MyHandler(this); usbManager = GetSystemService(Context.UsbService) as UsbManager; PowerManager powerManager = GetSystemService(PowerService) as PowerManager; wakeLock = powerManager.NewWakeLock(WakeLockFlags.ScreenDim, TAG); }
public void MultipleTransientReferences() { MyHandler handler = new MyHandler( model ); handler.Init( kernel ); object instance1 = handler.Resolve(); object instance2 = handler.Resolve(); object instance3 = handler.Resolve(); AssertNotNull( instance1 ); AssertNotNull( instance2 ); AssertNotNull( instance3 ); Assert( handler.IsOwner( instance1 ) ); Assert( handler.IsOwner( instance2 ) ); Assert( handler.IsOwner( instance3 ) ); Assert( !handler.IsOwner( new object() ) ); handler.Release( instance3 ); Assert( !handler.IsOwner( instance3 ) ); handler.Release( instance2 ); Assert( !handler.IsOwner( instance2 ) ); handler.Release( instance1 ); Assert( !handler.IsOwner( instance1 ) ); }
public void AddTest() { var pp = new Pipeline(); var h1 = new MyHandler(); var h2 = new MyHandler(); var h3 = new MyHandler(); pp.Add(h1); pp.Add(h3); pp.Add(h2); Assert.Equal(3, pp.Handlers.Count); Assert.Equal(h1, pp.Handlers[0]); Assert.Equal(h2, pp.Handlers[2]); Assert.Equal(h3, pp.Handlers[1]); Assert.Null(h1.Prev); Assert.Equal(h3, h1.Next); Assert.Equal(h1, h3.Prev); Assert.Equal(h2, h3.Next); Assert.Equal(h3, h2.Prev); Assert.Null(h2.Next); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.MyButton); button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; imageView = (ImageView)FindViewById(Resource.Id.img_butterfly); mh = new MyHandler(this); // 如果设置src属性,则Background为空 if (imageView.Background == null) { Log.Debug(TAG, "Background为空!"); } butterfly = (AnimationDrawable)imageView.Background; // 如果设置了Background属性,则 Drawable为空 if (imageView.Drawable == null) { Log.Debug(TAG, "Drawable为空!"); } imageView.Click += imgOnClick; }
private static void Main() { var handler = new MyHandler(new ApplicationHost()); handler.Start(); handler.Stop(); }
public async Task VerifyHandlerResult() { var handler = new MyHandler(); var context = new TestableMessageHandlerContext(); await handler.Handle(new(), context); await Verify(context); }
public HandlerTypeInvokerTests() { _di = Substitute.For <IContainerScope>(); _err = Substitute.For <IFailedMessagesQueue>(); _di.BeginLifetimeScope().Returns(_di); _handler = new MyHandler(); _di.Resolve(typeof(MyHandler)).Returns(_handler); _sut = new HandlerTypeInvoker(typeof(MyHandler), _di, new BusAuditor(NullStorage.Instance), _err); }
public HandlerTypeInvokerTests() { _di = Substitute.For<IContainerScope>(); _err = Substitute.For<IFailedMessagesQueue>(); _di.BeginLifetimeScope().Returns(_di); _handler=new MyHandler(); _di.Resolve(typeof (MyHandler)).Returns(_handler); _sut =new HandlerTypeInvoker(typeof(MyHandler),_di,new BusAuditor(NullStorage.Instance), _err); }
public static int Agr(List <int> list, MyHandler myHandler) { int result = 0; foreach (var item in list) { result += myHandler(item); } return(result); }
public static int Agr(List <int> list, MyHandler handler) //динамический метод, в который можно передать другой метод или лямбда выражение { int result = 0; foreach (var item in list) { result += handler(item); } return(result); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Utils.InitPath(this); handler = new MyHandler(this); dlg = new ProgressDialog(this); Utils.InitWS(); }
public async Task VerifyHandlerResult() { var handler = new MyHandler(); var context = new TestableMessageHandlerContext(); await handler.Handle(new MyRequest(), context) .ConfigureAwait(false); TestContextVerifier.Verify(context); }
public CustomScanner(Context context) : base(context) { UsbConnection = new MyServiceConnection(this); mUsbReceiver = new MyBroadcastReceiver(); mHandler = new MyHandler(this); IsTurned = false; SetFilters(); // Start listening notifications from UsbService StartService(typeof(WrapperUsbService), UsbConnection, null); }
public Castle_Interception_Test() { _container = new WindsorContainer(); _container.Register( Component.For <MyInterceptor>().LifestyleTransient(), Component.For <MyHandler>().Interceptors <MyInterceptor>().LifestyleTransient() ); _handler = _container.Resolve <MyHandler>(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Splash); MyHandler handler = new MyHandler(this); handler.SendEmptyMessageDelayed(0, 3000); }
private void OpenCamera() { if (CheckSelfPermission(Manifest.Permission.Camera) != Permission.Granted) { RequestCameraPermission(); return; } camera = Open(); Parameters parameters = camera.GetParameters(); parameters.PictureFormat = ImageFormatType.Jpeg; parameters.PreviewFormat = ImageFormatType.Nv21; if (parameters.SupportedFocusModes.Contains(Parameters.FocusModeContinuousVideo)) { parameters.FocusMode = Parameters.FocusModeContinuousVideo; } IList <Size> suportedPreviewSizes = parameters.SupportedPreviewSizes; int i = 0; for (i = 0; i < suportedPreviewSizes.Count; i++) { if (suportedPreviewSizes[i].Width < 1300) { break; } } parameters.SetPreviewSize(suportedPreviewSizes[i].Width, suportedPreviewSizes[i].Height); camera.SetParameters(parameters); camera.SetDisplayOrientation(90); camera.SetPreviewCallback(this); camera.SetPreviewDisplay(surface.Holder); camera.StartPreview(); //Get camera width previewWidth = parameters.PreviewSize.Width; //Get camera height previewHeight = parameters.PreviewSize.Height; //Resize SurfaceView Size float scaledHeight = previewWidth * 1.0f * surface.Width / previewHeight; float prevHeight = surface.Height; ViewGroup.LayoutParams lp = surface.LayoutParameters; lp.Width = surface.Width; lp.Height = (int)scaledHeight; surface.LayoutParameters = lp; surface.Top = (int)((prevHeight - scaledHeight) / 2); surface.DrawingCacheEnabled = true; handlerThread = new HandlerThread("background"); handlerThread.Start(); //backgroundHandler = new MyHandler(handlerThread.Looper); backgroundHandler = new MyHandler(Looper.MainLooper); }
public void RunTest() { var del = new MyHandler(Method); if (del is Delegate) { Console.WriteLine(@"del is a delegate."); } else { Console.WriteLine("del is not a delegate"); } }
/* * Returns false if password doesn't match or an error occurs */ public override bool Logout(string nickname, string password) { if (!DBController.PasswordMatch(conn, nickname, password)) { return(false); } IClient client = new LoggedClient(nickname, DBController.GetUserRealName(conn, nickname), null, 0); MyHandler?.Invoke(client); bool sessionEnded = DBController.EndSession(conn, nickname); return(sessionEnded); }
static void Main(string[] args) { var lesson = new Lesson("Programming"); lesson.Started += (sender, date) => { Console.WriteLine(sender); Console.WriteLine(date); }; lesson.Start(); var list = new List <int>(); for (int i = 0; i < 100; i++) { list.Add(i); } var res = list.Aggregate((x, y) => x + y); Console.WriteLine(res); var result1 = Agr(list, delegate(int i) { var r = i * i; Console.WriteLine(r); return(r); }); var result2 = Agr(list, x => x * x * x); MyHandler handler = delegate(int i) { var r = i * i; Console.WriteLine(r); return(r); }; handler(88); MyHandler lambdaHandler = (i) => /*i * i;*/ { var r = i * i; Console.WriteLine(r); return(r); }; lambdaHandler(99); Console.ReadLine(); }
/* * Returns false if password doesn't match or an error occurs */ public override bool Login(string nickname, string password, string ip, int port) { if (!DBController.PasswordMatch(conn, nickname, password)) { return(false); } bool sessionCreated = DBController.CreateUpdateSession(conn, nickname, ip, port); if (sessionCreated) { MyHandler?.Invoke(new LoggedClient(nickname, DBController.GetUserRealName(conn, nickname), ip, port)); } return(sessionCreated); }
/* * protected override void OnCreate (Bundle bundle) * { * base.OnCreate (bundle); * FrameLayout overlayFramelayout = new FrameLayout(ctx); * overlayFramelayout.Background = (Drawable)Android.Resource.Color.Black; * //SetContentView(overlayFramelayout); * //View view = LayoutInflater.Inflate() * * tipWindow = new PopupWindow(ctx); * inflater = (LayoutInflater)ctx.GetSystemService(Context.LayoutInflaterService); * //contentView = inflater.Inflate (Resource.Layout.custom_tooltip, null); * contentView = inflater.Inflate(Resource.Layout.custom_tooltip, overlayFramelayout, false); * overlayFramelayout.AddView(contentView); * }*/ public void showToolTip(View anchor) { Console.WriteLine("USAO BREE"); tipWindow.Height = ViewGroup.LayoutParams.WrapContent; //it was actionbar before tipWindow.Width = ViewGroup.LayoutParams.WrapContent; tipWindow.OutsideTouchable = false; tipWindow.Focusable = true; tipWindow.SetBackgroundDrawable(new BitmapDrawable()); //tipWindow.SetBackgroundDrawable(new ColorDrawable(Color.Transparent)); tipWindow.ContentView = contentView; tipWindow.AnimationStyle = Resource.Style.animationName; /* * Rect anchor_rect = new Rect(positionX, positionY, positionX + positionY, positionY + positionY); * * contentView.Measure(ActionBar.LayoutParams.WrapContent, ActionBar.LayoutParams.WrapContent); * * int contentViewheight = contentView.MeasuredHeight; * int contentViewwidth = contentView.MeasuredWidth; * * int position_x = anchor_rect.CenterX() - (contentViewwidth / 2); * int position_y = anchor_rect.Bottom - (anchor_rect.Height() / 2); * * //tipWindow.ShowAtLocation(anchor, GravityFlags.NoGravity, position_x, position_y); * */ int[] screen_pos = new int[2]; anchor.GetLocationOnScreen(screen_pos); Rect anchor_rect = new Rect(screen_pos[0], screen_pos[1], screen_pos[0] + anchor.Width, screen_pos[1] + anchor.Height); contentView.Measure(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); int contentViewheight = contentView.MeasuredHeight; int contentViewwidth = contentView.MeasuredWidth; int position_x = anchor_rect.CenterX() - (contentViewwidth / 2); int position_y = anchor_rect.Bottom - (anchor_rect.Height() / 2); tipWindow.ShowAtLocation(anchor, GravityFlags.NoGravity, position_x, position_y); // tipWindow.ShowAtLocation(anchor, GravityFlags.Top, 0, 1300); Console.WriteLine("Anchor: " + screen_pos[0] + " pos 1 " + screen_pos[1] + "contentViewHeigth" + contentViewheight + "contenttViewWidth" + contentViewwidth); Handler h = new MyHandler(this); //h.SendEmptyMessageDelayed(MSG_DISMISS_TOOLTIP, 4000); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); api = WXAPIFactory.CreateWXAPI(this, appID, true); handler = new MyHandler(this); try { Intent intent = this.Intent; bool b = api.HandleIntent(intent, this); } catch (Exception e) { Log.Error(TAG, e.StackTrace); } }
public void TestProxy() { InvocationHandler handler = new MyHandler(); MyTestInterface inter = (MyTestInterface)Proxy.NewProxyInstance(typeof(MyTestInterface), handler); Assert.AreEqual("TestTwoArgs foo bar", inter.TestTwoArgs("foo", "bar")); IList<object> temp = new List<object>(); inter.TestVoid(temp); Assert.AreEqual("my void result", temp[0]); Assert.AreEqual(10, inter.TestPrimitive(10)); Assert.AreEqual(1000L, inter.TestStruct(new DateTime(1000)).Ticks); inter.TestProperty = "my property"; Assert.AreEqual("my property", inter.TestProperty); }
public void SurfaceDestroyed(ISurfaceHolder holder) { holder.RemoveCallback(this); if (camera != null) { camera.SetPreviewCallback(null); camera.StopPreview(); camera.Release(); camera = null; } if (handlerThread != null) { handlerThread.QuitSafely(); handlerThread.Join(); handlerThread = null; } backgroundHandler = null; }
protected void loadData() { var Endpoint = "http://47.91.249.226:8000/api/Video/GetAllVideos"; MyTask myTask = new MyTask(); myTask.SetLitener(this); myTask.Execute(Endpoint); //启动异步任务 //Action action = () => //{ // OkHttpClient client = new OkHttpClient(); // // Create request for remote resource. // Request request = new Request.Builder() // .Url(Endpoint) // .Build(); // // Execute the request and retrieve the response. // Response response = client.NewCall(request).ExecuteAsync().Result; // // Deserialize HTTP response to concrete type. // string body = response.Body().StringAsync().Result; // list = new List<VideoModel>(); // list = JsonConvert.DeserializeObject<List<VideoModel>>(body); //}; _myHandler = new MyHandler(GetValue); //在主线程实例化一个Handler对象 //RetrofitHelper.getBiliAppAPI() // .getVideoDetails(av) // .compose(this.bindToLifecycle()) // .subscribeOn(Schedulers.io()) // .observeOn(AndroidSchedulers.mainThread()) // .subscribe(videoDetails-> { // mVideoDetailsInfo = videoDetails.getData(); // finishTask(); //}, throwable-> { //}); finishTask(); }
public void should_consume_event_in_the_classic_way() { var sut = new SomeEventBasedClass(); var messages = new List <string>(); MyHandler myHandler = (sender, args) => messages.Add(args.SomeField); sut.Sent += myHandler; sut.Send("message 1"); sut.Send("message 2"); sut.Send("message 3"); messages[0].Should().Be("message 1"); messages[1].Should().Be("message 2"); messages[2].Should().Be("message 3"); sut.Sent -= myHandler; }
public void SendAsync_NullRequest_ThrowsArgumentNullException() { RemoteInvoke(() => { var diagnosticListenerObserver = new FakeDiagnosticListenerObserver(null); using (DiagnosticListener.AllListeners.Subscribe(diagnosticListenerObserver)) { diagnosticListenerObserver.Enable(); using (MyHandler handler = new MyHandler()) { Assert.ThrowsAsync <ArgumentNullException>(() => handler.SendAsync(null)).Wait(); } } diagnosticListenerObserver.Disable(); return(SuccessExitCode); }).Dispose(); }
static void Main(string[] args) { if (int.TryParse(Console.ReadLine(), out int result)) { MyHandler handler = (i) => //i*i; // Эта строка и нижняя процедура - синонимичны //MyHandler handler = delegate (int i) // (тип_аргумента аргумент1, тип_аргумента аргумент2...) { // Реализация анонимного метода var r = i * i; Console.WriteLine(r); return(r); }; handler += Method; handler(result); } Console.ReadLine(); }
public void TestProxy() { InvocationHandler handler = new MyHandler(); MyTestInterface inter = (MyTestInterface)Proxy.NewProxyInstance(typeof(MyTestInterface), handler); Assert.AreEqual("TestTwoArgs foo bar", inter.TestTwoArgs("foo", "bar")); IList <object> temp = new List <object>(); inter.TestVoid(temp); Assert.AreEqual("my void result", temp[0]); Assert.AreEqual(10, inter.TestPrimitive(10)); Assert.AreEqual(1000L, inter.TestStruct(new DateTime(1000)).Ticks); inter.TestProperty = "my property"; Assert.AreEqual("my property", inter.TestProperty); }
public void TransientReferences() { MyHandler handler = new MyHandler( model ); handler.Init( kernel ); object instance = handler.Resolve(); AssertNotNull( instance ); Assert( handler.IsOwner( instance ) ); handler.Release( instance ); Assert( !handler.IsOwner( instance ) ); }
internal void ExecuteHandler(MyHandler handler) { }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); //Initialization // Get local Bluetooth adapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter; DeviceName = bluetoothAdapter.Name; handle = new MyHandler (this); messagesViewAdapter = new ArrayAdapter<string>(this, Resource.Layout.message); // If the adapter is null, then Bluetooth is not supported if (bluetoothAdapter == null) { Toast.MakeText (this, "Bluetooth is not available", ToastLength.Long).Show (); Finish (); return; } BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter; #region Home Screen UI stuff //set the content view to the home scree ui SetContentView (Resource.Layout.Home); //button handler for the only button - Math and Science Extravaganze with friends var butt = FindViewById<Button> (Resource.Id.gameButton); butt.Click += (object sender, EventArgs e) => { //build a dialog to ask for a new game or an exsiting game AlertDialog.Builder builder = new AlertDialog.Builder(this, 5); builder.SetTitle("Start Game?"); builder.SetMessage("Do you want to start a new game or connect to an exsiting one?"); //if new game launch the new game view which will get the number of players and the name of the device builder.SetPositiveButton("New Game", (s, ev) => { SetContentView(Resource.Layout.TextInput); var number = FindViewById<EditText>(Resource.Id.numPlayers); var name = FindViewById<EditText>(Resource.Id.editText1); var button = FindViewById<Button>(Resource.Id.createButton); button.Click += (object sender1, EventArgs e1) => { Console.WriteLine(number.Text.ToString()); Console.WriteLine(name.Text.ToString()); adapter.SetName(name.Text.ToString()); maxDevices = Integer.ParseInt(number.Text.ToString()); //enable discoverability for ever EnsureDiscoverable(); dialogSpin = new ProgressDialog(this, 5); dialogSpin.SetProgressStyle(ProgressDialogStyle.Spinner); dialogSpin.SetMessage("Waiting for Other Devices"); dialogSpin.Indeterminate = true; SetContentView(Resource.Layout.WaitView); dialogSpin.Show(); }; }); //if exsiting game then start the device finding dialog and initiate a connection builder.SetNegativeButton("Existing Game", (s, ev) => { activeReturn = true; Intent serverIntent = new Intent(this, typeof(DeviceListActivity)); StartActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); }); //show the dialog Dialog dialog = builder.Create(); dialog.Show(); }; #endregion }
public void ImplementsContract_returns_false_when_unknown() { var handler = new MyHandler(); Assert.False(handler.ImplementsContract("My.Fake.Contract")); }
public void ImplementsContract_returns_false_when_not_implemented() { var handler = new MyHandler(); Assert.False(handler.ImplementsContract(typeof(ICustomHandler).FullName)); }
public void ImplementsContract_returns_true_when_implemented() { var handler = new MyHandler(); Assert.True(handler.ImplementsContract(typeof(IResultHandler).FullName)); }
public LocalService() { mHandler = new MyHandler(this); }
public BluetoothChat() { mHandler = new MyHandler(this); }
public Beam () { mHandler = new MyHandler (HandlerHandleMessage); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Create and attach the view that is responsible for painting. mView = new PaintView (this); SetContentView (mView); mView.RequestFocus (); // Restore the fading option if we are being thawed from a // previously saved state. Note that we are not currently remembering // the contents of the bitmap. if (bundle != null) { mFading = bundle.GetBoolean ("fading", true); mView.mColorIndex = bundle.GetInt ("color", 0); } else { mFading = true; mView.mColorIndex = 0; } mHandler = new MyHandler (this); }