private int GetClippedWidth(int viewHolderWidth, float dX, int measured) { if (viewHolderWidth <= 0) { return(0); } return(Math.Min(measured, (int)Math.Ceil(Math.Abs(dX)))); }
public bool OnTouch(View v, MotionEvent e) { _scaleDetector.OnTouchEvent(e); PointF curr = new PointF(e.GetX(), e.GetY()); switch (e.Action) { case MotionEventActions.Down: _last.Set(curr); _start.Set(_last); _mode = Dragging; break; case MotionEventActions.Move: if (_mode == Dragging) { float deltaX = curr.X - _last.X; float deltaY = curr.Y - _last.Y; float fixTransX = GetFixDragTrans(deltaX, _viewWidth, OrigWidth * _saveScale); float fixTransY = GetFixDragTrans(deltaY, _viewHeight, OrigHeight * _saveScale); Matrix.PostTranslate(fixTransX, fixTransY); FixTrans(); _last.Set(curr.X, curr.Y); } break; case MotionEventActions.Up: _mode = None; var xDiff = (int)Math.Abs(curr.X - _start.X); var yDiff = (int)Math.Abs(curr.Y - _start.Y); if (xDiff < Clicking && yDiff < Clicking) { PerformClick(); } break; case MotionEventActions.PointerUp: _mode = None; break; } ImageMatrix = _matrix; Invalidate(); return(true); // indicate event was handled }
public float distortInverse(float radius) { float r0 = radius / 0.9F; float r1 = radius * 0.9F; float dr0 = radius - distort(r0); while (Math.Abs(r1 - r0) > 0.0001D) { float dr1 = radius - distort(r1); float r2 = r1 - dr1 * ((r1 - r0) / (dr1 - dr0)); r0 = r1; r1 = r2; dr0 = dr1; } return(r1); }
public static int largestAbsComponent(Vector3d v) { double xAbs = Math.Abs(v.x); double yAbs = Math.Abs(v.y); double zAbs = Math.Abs(v.z); if (xAbs > yAbs) { if (xAbs > zAbs) { return(0); } return(2); } if (yAbs > zAbs) { return(1); } return(2); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); int hourHeight = mHourHeight; Paint dividerPaint = mDividerPaint; dividerPaint.Color = mDividerColor; dividerPaint.SetStyle(Paint.Style.Fill); Paint labelPaint = mLabelPaint; labelPaint.Color = mLabelColor; labelPaint.TextSize = mLabelTextSize; labelPaint.SetTypeface(Typeface.DefaultBold); labelPaint.AntiAlias = true; var metrics = labelPaint.GetFontMetricsInt(); int labelHeight = Math.Abs(metrics.Ascent); int labelOffset = labelHeight + mLabelPaddingLeft; int right = Right; // Walk left side of canvas drawing timestamps int hours = mEndHour - mStartHour; for (int i = 0; i < hours; i++) { int dividerY = hourHeight * i; int nextDividerY = hourHeight * (i + 1); canvas.DrawLine(0, dividerY, right, dividerY, dividerPaint); // draw text title for timestamp canvas.DrawRect(0, dividerY, mHeaderWidth, nextDividerY, dividerPaint); // TODO: localize these labels better, including handling // 24-hour mode when set in framework. int hour = mStartHour + i; String label; if (hour == 0) { label = "12am"; } else if (hour <= 11) { label = hour + "am"; } else if (hour == 12) { label = "12pm"; } else { label = (hour - 12) + "pm"; } float labelWidth = labelPaint.MeasureText(label); canvas.DrawText(label, 0, label.Length, mHeaderWidth - labelWidth - mLabelPaddingLeft, dividerY + labelOffset, labelPaint); } }