Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Android;
- using Android.App;
- using Android.OS;
- using Android.Views;
- using Android.Content; // vanwege Context
- using Android.Support.V7.App;
- using Android.Runtime;
- using Android.Widget;
- using Android.Graphics; // vanwege Color
- using Android.Hardware;
- using System;
- using System.Collections.Generic;
- namespace App4
- {
- [Activity(Label = "Running", MainLauncher = true)]
- public class RunningApp : Activity
- {
- Button center;
- Button start;
- Button clear;
- LinearLayout buttonlayout;
- LinearLayout screenlayout;
- Mapview Map;
- public void Buttons()
- {
- this.center = new Button(this);
- this.start = new Button(this);
- this.clear = new Button(this);
- this.center.Text = "Center";
- this.start.Text = "Start";
- this.clear.Text = "Clear";
- this.center.TextSize = 10;
- this.start.TextSize = 10;
- this.clear.TextSize = 10;
- this.center.Click += this.centerklick;
- this.start.Click += this.startklick;
- this.clear.Click += this.clearklick;
- }
- public void centerklick(object o, EventArgs ea)
- {
- Map.CenterMap();
- }
- public void startklick(object o, EventArgs ea)
- { }
- public void clearklick(object o, EventArgs ea)
- { }
- protected override void OnCreate(Bundle b)
- {
- base.OnCreate(b);
- Buttons();
- Map = new Mapview(this);
- //Linerlayout
- buttonlayout = new LinearLayout(this);
- screenlayout = new LinearLayout(this);
- buttonlayout.Orientation = Orientation.Horizontal;
- buttonlayout.AddView(center);
- buttonlayout.AddView(start);
- buttonlayout.AddView(clear);
- screenlayout.Orientation = Orientation.Vertical;
- screenlayout.AddView(buttonlayout);
- screenlayout.AddView(Map);
- this.SetContentView(screenlayout);
- }
- }
- public class Mapview : View, GestureDetector.IOnGestureListener, ScaleGestureDetector.IOnScaleGestureListener
- {
- Bitmap PG;
- float scale;
- float d;
- float midx;
- float midy;
- float max;
- PointF centrum = new PointF(139000, 455500);
- Paint verf = new Paint();
- GestureDetector detector;
- ScaleGestureDetector Scaledetector;
- public Mapview(Context c) : base(c)
- {
- this.SetBackgroundColor(Color.Blue);
- detector = new GestureDetector(c, this);
- Scaledetector = new ScaleGestureDetector(c, this);
- BitmapFactory.Options opt = new BitmapFactory.Options();
- opt.InScaled = false;
- PG = BitmapFactory.DecodeResource(c.Resources, Resource.Drawable.Utrecht, opt);
- this.Touch += touched;
- }
- List<PointF> punten = new List<PointF>();
- public void touched(object o,TouchEventArgs tea)
- {
- detector.OnTouchEvent(tea.Event);
- //Scaledetector.OnTouchEvent(tea.Event);
- }
- public void CenterMap()
- {
- /*mat.PostTranslate(-(139000 - 136000) * 0.4f, -(455500 - 458000) *0.4f);
- mat.PostScale(this.scale, this.scale);
- mat.PostTranslate(this.Width / 2, this.Height / 2);*/
- }
- bool j = true;
- protected override void OnDraw(Canvas canvas)
- {
- Matrix mat = new Matrix();
- if (j)
- {
- scale = Math.Max(max, Math.Min(scale, 6f));
- if (scale == 0)
- scale = Math.Max(((float)this.Width) / this.PG.Width,
- ((float)this.Height) / this.PG.Height);
- j = false;
- }
- base.OnDraw(canvas);
- max = (float)((decimal)this.Height / (decimal)PG.Height);
- midx = (centrum.X - 136000) * 0.4f;
- midy = -(centrum.Y - 458000) * 0.4f;
- mat.PostTranslate(-midx, -midy);
- mat.PostScale(this.scale, this.scale);
- mat.PostTranslate(this.Width / 2, this.Height / 2);
- canvas.DrawBitmap(this.PG, mat, verf);
- }
- public bool OnDown(MotionEvent e)
- {
- /*float dx = e.Event.GetX();
- float dy =
- float ax = (dx / this.scale) / 0.2f; // Distance to the centre in metres
- float ay = (dy / this.scale) / 0.2f;
- this.centrum = new PointF(centrum.X + ax, centrum.Y - ay);
- */
- return true;
- }
- public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
- {
- return true;
- }
- public void OnLongPress(MotionEvent e)
- {
- }
- public bool OnScroll(MotionEvent e1, MotionEvent e2, float dx, float dy)
- {
- float ax = 0;
- float ay = 0;
- ax = (dx / this.scale) / 0.2f; // Distance to the centre in metres
- ay = (dy / this.scale) / 0.2f;
- this.centrum = new PointF(centrum.X + ax, centrum.Y - ay);
- this.Invalidate();
- return (true);
- }
- public void OnShowPress(MotionEvent e)
- {
- }
- public bool OnSingleTapUp(MotionEvent e)
- {
- return true;
- }
- public bool OnScale(ScaleGestureDetector detector)
- {
- this.scale *= detector.ScaleFactor;
- this.Invalidate();
- return true;
- }
- public bool OnScaleBegin(ScaleGestureDetector detector)
- {
- return true;
- }
- public void OnScaleEnd(ScaleGestureDetector detector)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement