public override void ComputeScroll() { // if (IsAttachedToWindow) { // TODO [email protected]: This bug causes an exception to be thrown when the scroller is disposes. // this usually happens when starting a remote view // L.E(this, "Tried to compute scroll while swipe menu was not attached to the a window."); // return; // } try { if (isOpen) { if (openScroller.ComputeScrollOffset()) { Swipe(openScroller.CurrX * (int)recyclerView.swipeDirection); PostInvalidate(); } } else { if (closeScroller.ComputeScrollOffset()) { Swipe((int)((baseX - closeScroller.CurrX) * (int)recyclerView.swipeDirection)); PostInvalidate(); } } } catch (Exception e) { L.E(this, "Tried to compute scroll while swipe menu was not attached to a window", e); } }
public SensorPropertyViewHolder(SwipeRecyclerView recyclerView, int foregroundLayout) : base(recyclerView, foregroundLayout, Resource.Layout.view_delete) { var button = background as Button; button.SetText(Resource.String.remove); button.SetOnClickListener(new ViewClickAction((view) => { L.D(this, "Removing sensor property: " + sensorPropertyRecord.sensorProperty); sensorPropertyRecord.manifold.RemoveSensorProperty(sensorPropertyRecord.sensorProperty); })); }
/// <summary> /// Called when a sensor mount is clicked in the analyzer. /// </summary> /// <param name="view">View.</param> /// <param name="analyzer">Analyzer.</param> /// <param name="index">Index.</param> private void OnSensorMountLongClicked(AnalyzerView view, Analyzer analyzer, int index) { if (!analyzer.isEditable) { return; } if (analyzer.HasSensorAt(index)) { analyzerView.StartDraggingSensorMount(index); } else { ShowAddFromDialog(analyzer, index); } L.D(this, "Analyzer view callback sensor mount long clicked at index: " + index); }
/// <summary> /// Views the in superheat subcool activity. /// </summary> /// <param name="">.</param> private void ViewInSuperheatSubcoolActivity(Manifold manifold, ISensorProperty sensorProperty) { var side = Analyzer.ESide.Low; if (!analyzer.GetSideOfManifold(manifold, out side)) { Error(GetString(Resource.String.analyzer_error_failed_to_launch_shsc_missing_manifold)); return; } // If the manifold does not have a secondary sensor, then we will need to query whether or not the analyzer has // space to accept the returned sensor. If it does not, then we cannot open the activity safely. if (manifold.secondarySensor == null && !analyzer.CanAddSensorToSide(side)) { var adb = new IONAlertDialog(Activity, Resource.String.error); adb.SetMessage(string.Format(GetString(Resource.String.analyzer_error_failed_to_launch_shsc_analyzer_full_1sarg), side.ToLocalizedString(Activity))); adb.SetNegativeButton(Resource.String.ok, (obj, args) => { var dialog = obj as Android.App.Dialog; dialog.Dismiss(); }); adb.Show(); return; } var sensor = sensorProperty.sensor; var i = new Intent(Activity, typeof(SuperheatSubcoolActivity)); i.SetAction(Intent.ActionPick); i.PutExtra(SuperheatSubcoolActivity.EXTRA_LOCK_FLUID, true); i.PutExtra(SuperheatSubcoolActivity.EXTRA_FLUID_NAME, manifold.ptChart.fluid.name); i.PutExtra(SuperheatSubcoolActivity.EXTRA_FLUID_STATE, (int)analyzer.SideAsFluidState(side)); switch (sensor.type) { case ESensorType.Pressure: i.PutExtra(SuperheatSubcoolActivity.EXTRA_ANALYZER_MANIFOLD, (int)side); if (ion is RemoteION) { StartActivity(i); } else { StartActivityForResult(i, EncodeSuperheatSubcoolRequest(side)); } break; case ESensorType.Temperature: i.PutExtra(SuperheatSubcoolActivity.EXTRA_ANALYZER_MANIFOLD, (int)side); if (ion is RemoteION) { StartActivity(i); } else { StartActivityForResult(i, EncodeSuperheatSubcoolRequest(side)); } break; default: var msg = string.Format(GetString(Resource.String.analyzer_error_invalid_sensor_type), sensor.type.GetTypeString()); L.E(this, msg); Alert(msg); break; } }
/// <Docs>The integer request code originally supplied to /// startActivityForResult(), allowing you to identify who this /// result came from.</Docs> /// <param name="data">An Intent, which can return result data to the caller /// (various data can be attached to Intent "extras").</param> /// <summary> /// Raises the activity result event. /// </summary> /// <param name="requestCode">Request code.</param> /// <param name="resultCode">Result code.</param> public override void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (Result.Ok != resultCode) { return; } var request = requestCode & MASK_REQUEST; switch (request) { case REQUEST_SHOW_SUPERHEAT_SUBCOOL: { var side = (Analyzer.ESide) unchecked ((requestCode & MASK_SIDE) >> 8); var manifold = analyzer.GetManifoldFromSide(side); if (analyzer.HasSensor(manifold.secondarySensor)) { // TODO [email protected]: Is this right? Analyzer.ESide ss; if (!analyzer.GetSideOfSensor(manifold.secondarySensor, out ss)) { Appion.Commons.Util.Log.E(this, "Failed to get side of sensor"); return; } // The user returned from the SHSC activity with a sensor. if (ss != side) { // The sensor that the user returned with is not on the side of the manifold. if (analyzer.IsSideFull(side)) { // We cannot swap the side of the sensor; the side is full. L.E(this, "Tried to add sensor from opposite side to this side."); Toast.MakeText(Activity, Resource.String.analyzer_error_failed_to_link_sensors, ToastLength.Long).Show(); manifold.SetSecondarySensor(null); } else { analyzer.SwapSensors(analyzer.IndexOfSensor(manifold.secondarySensor), analyzer.NextEmptySensorIndex(side), true); } } else if (!analyzer.HasSensor(manifold.secondarySensor) && analyzer.IsSideFull(side)) { Toast.MakeText(Activity, string.Format(GetString(Resource.String.analyzer_side_full_1sarg), side), ToastLength.Long).Show(); manifold.SetSecondarySensor(null); } else { if (!analyzer.IsSensorOnSide(manifold.secondarySensor, side)) { var si = analyzer.IndexOfSensor(manifold.secondarySensor); var di = analyzer.NextEmptySensorIndex(side); // analyzerView.SwapSensorMounts(di, si); analyzer.SwapSensors(di, si, true); } } } else { analyzer.AddSensorToSide(side, manifold.secondarySensor); } } break; case REQUEST_MANIFOLD_ON_SIDE: { Toast.MakeText(Activity, "DEVICE MANAGER WAS REMOVED! IMPLEMENT DEVICE SELECTION LIST", ToastLength.Short).Show(); /* * var mside = (Analyzer.ESide)unchecked((requestCode & MASK_SIDE) >> 8); * var msp = data.GetParcelableExtra(DeviceManagerActivity.EXTRA_SENSOR) as SensorParcelable; * var s = msp.Get(ion); * * TrySetManifold(mside, s); */ } break; default: L.D(this, "Unknown request: " + request); break; } }
public override bool OnInterceptTouchEvent(MotionEvent ev) { if (ev.Action != MotionEventActions.Down && touchView == null) { return(base.OnInterceptTouchEvent(ev)); } else if (!swipingEnabled) { return(base.OnInterceptTouchEvent(ev)); } switch (ev.Action) { case MotionEventActions.Down: dx = dy = 0.0f; startClickTime = DateTime.Now; int oldPos = touchPosition; downX = ev.GetX(); downY = ev.GetY(); touchState = ETouchState.None; touchPosition = GetChildAdapterPosition(FindChildViewUnder(downX, downY)); if (touchPosition == oldPos && touchView != null && touchView.isOpen) { if (!touchView.OnTouchEvent(ev)) { touchState = ETouchState.X; touchView.OnSwipe(ev); } } // Find the touched child view View view = null; var vh = FindViewHolderForAdapterPosition(touchPosition); if (vh != null) { view = vh.ItemView; } if (touchPosition != oldPos && touchView != null && touchView.isOpen) { touchView.Close(); touchView = null; var cancelEvent = MotionEvent.Obtain(ev); cancelEvent.Action = MotionEventActions.Cancel; base.OnTouchEvent(cancelEvent); L.D(this, "Returning true"); return(true); } touchView = view as SwipeMenuLayout; if (touchView != null) { touchView.recyclerView = this; touchView.OnSwipe(ev); } break; // MotionEventActions.Down case MotionEventActions.Move: dx = Math.Abs(ev.GetX() - downX); dy = Math.Abs(ev.GetY() - downY); if (touchState == ETouchState.X && touchView.isSwipeEnabled) { touchView.OnSwipe(ev); ev.Action = MotionEventActions.Cancel; base.OnTouchEvent(ev); } else if (touchState == ETouchState.None && touchView.isSwipeEnabled) { if (Math.Abs(dy) > viewConfig.ScaledTouchSlop) { touchState = ETouchState.Y; } else if (dx > viewConfig.ScaledTouchSlop) { touchState = ETouchState.X; NotifySwipeStart(touchPosition); } } break; // MotionEventActions.Move case MotionEventActions.Up: bool isCloseOnUpEvent = false; if (touchState == ETouchState.X && touchView.isSwipeEnabled) { isCloseOnUpEvent = !touchView.OnSwipe(ev); NotifySwipeEnd(touchPosition); if (!touchView.isOpen) { touchPosition = -1; touchView = null; } ev.Action = MotionEventActions.Cancel; base.OnTouchEvent(ev); } var clickDuration = DateTime.Now - startClickTime; var isOutOfTime = clickDuration > TimeSpan.FromMilliseconds(ViewConfiguration.LongPressTimeout); var isOutX = dx > viewConfig.ScaledTouchSlop; var isOutY = dy > viewConfig.ScaledTouchSlop; if (isOutOfTime || isOutX || isOutY) { return(true); } else { var evX = ev.GetX(); var evY = ev.GetY(); var upView = FindChildViewUnder(evX, evY) as SwipeMenuLayout; if (upView != null) { var x = evX - upView.Left; var y = evY - upView.Top; var mv = upView.background; var tx = mv.TranslationY; var ty = mv.TranslationX; if (!(x >= mv.Left + tx && x <= mv.Right + tx && y >= mv.Top + ty && y <= mv.Bottom + ty) && isCloseOnUpEvent) { return(true); } } } break; // MotionEventActions.Up; case MotionEventActions.Cancel: if (touchView != null && touchView.isSwipeEnabled) { ev.Action = MotionEventActions.Up; touchView.OnSwipe(ev); } break; // MotionEventActions.Cancel } return(base.OnInterceptTouchEvent(ev)); }