Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. using Android;
  2. using Android.App;
  3. using Android.OS;
  4. using Android.Views;
  5. using Android.Content; // vanwege Context
  6. using Android.Support.V7.App;
  7. using Android.Runtime;
  8. using Android.Widget;
  9. using Android.Graphics; // vanwege Color
  10. using Android.Hardware;
  11.  
  12. using System;
  13. using System.Collections.Generic;
  14.  
  15. namespace App4
  16. {
  17. [Activity(Label = "Running", MainLauncher = true)]
  18. public class RunningApp : Activity
  19.  
  20. {
  21. Button center;
  22. Button start;
  23. Button clear;
  24.  
  25. LinearLayout buttonlayout;
  26. LinearLayout screenlayout;
  27. Mapview Map;
  28.  
  29. public void Buttons()
  30. {
  31. this.center = new Button(this);
  32. this.start = new Button(this);
  33. this.clear = new Button(this);
  34. this.center.Text = "Center";
  35. this.start.Text = "Start";
  36. this.clear.Text = "Clear";
  37. this.center.TextSize = 10;
  38. this.start.TextSize = 10;
  39. this.clear.TextSize = 10;
  40. this.center.Click += this.centerklick;
  41. this.start.Click += this.startklick;
  42. this.clear.Click += this.clearklick;
  43.  
  44.  
  45. }
  46. public void centerklick(object o, EventArgs ea)
  47. {
  48. Map.CenterMap();
  49.  
  50. }
  51. public void startklick(object o, EventArgs ea)
  52. { }
  53. public void clearklick(object o, EventArgs ea)
  54. { }
  55. protected override void OnCreate(Bundle b)
  56. {
  57. base.OnCreate(b);
  58. Buttons();
  59.  
  60. Map = new Mapview(this);
  61. //Linerlayout
  62. buttonlayout = new LinearLayout(this);
  63. screenlayout = new LinearLayout(this);
  64.  
  65.  
  66. buttonlayout.Orientation = Orientation.Horizontal;
  67. buttonlayout.AddView(center);
  68. buttonlayout.AddView(start);
  69. buttonlayout.AddView(clear);
  70.  
  71.  
  72. screenlayout.Orientation = Orientation.Vertical;
  73.  
  74. screenlayout.AddView(buttonlayout);
  75. screenlayout.AddView(Map);
  76. this.SetContentView(screenlayout);
  77. }
  78. }
  79. public class Mapview : View, GestureDetector.IOnGestureListener, ScaleGestureDetector.IOnScaleGestureListener
  80. {
  81. Bitmap PG;
  82. float scale;
  83. float d;
  84. float midx;
  85. float midy;
  86. float max;
  87.  
  88. PointF centrum = new PointF(139000, 455500);
  89. Paint verf = new Paint();
  90. GestureDetector detector;
  91. ScaleGestureDetector Scaledetector;
  92. public Mapview(Context c) : base(c)
  93. {
  94.  
  95. this.SetBackgroundColor(Color.Blue);
  96. detector = new GestureDetector(c, this);
  97. Scaledetector = new ScaleGestureDetector(c, this);
  98. BitmapFactory.Options opt = new BitmapFactory.Options();
  99. opt.InScaled = false;
  100. PG = BitmapFactory.DecodeResource(c.Resources, Resource.Drawable.Utrecht, opt);
  101.  
  102.  
  103. this.Touch += touched;
  104. }
  105. List<PointF> punten = new List<PointF>();
  106. public void touched(object o,TouchEventArgs tea)
  107. {
  108.  
  109. detector.OnTouchEvent(tea.Event);
  110. //Scaledetector.OnTouchEvent(tea.Event);
  111. }
  112. public void CenterMap()
  113. {
  114. /*mat.PostTranslate(-(139000 - 136000) * 0.4f, -(455500 - 458000) *0.4f);
  115. mat.PostScale(this.scale, this.scale);
  116. mat.PostTranslate(this.Width / 2, this.Height / 2);*/
  117.  
  118. }
  119.  
  120. bool j = true;
  121. protected override void OnDraw(Canvas canvas)
  122. {
  123. Matrix mat = new Matrix();
  124.  
  125. if (j)
  126. {
  127. scale = Math.Max(max, Math.Min(scale, 6f));
  128.  
  129. if (scale == 0)
  130. scale = Math.Max(((float)this.Width) / this.PG.Width,
  131. ((float)this.Height) / this.PG.Height);
  132. j = false;
  133. }
  134.  
  135. base.OnDraw(canvas);
  136. max = (float)((decimal)this.Height / (decimal)PG.Height);
  137.  
  138. midx = (centrum.X - 136000) * 0.4f;
  139. midy = -(centrum.Y - 458000) * 0.4f;
  140.  
  141. mat.PostTranslate(-midx, -midy);
  142. mat.PostScale(this.scale, this.scale);
  143. mat.PostTranslate(this.Width / 2, this.Height / 2);
  144.  
  145.  
  146. canvas.DrawBitmap(this.PG, mat, verf);
  147.  
  148. }
  149.  
  150. public bool OnDown(MotionEvent e)
  151. {
  152. /*float dx = e.Event.GetX();
  153. float dy =
  154. float ax = (dx / this.scale) / 0.2f; // Distance to the centre in metres
  155. float ay = (dy / this.scale) / 0.2f;
  156.  
  157. this.centrum = new PointF(centrum.X + ax, centrum.Y - ay);
  158.  
  159. */
  160. return true;
  161. }
  162.  
  163. public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
  164. {
  165. return true;
  166. }
  167.  
  168. public void OnLongPress(MotionEvent e)
  169. {
  170. }
  171.  
  172. public bool OnScroll(MotionEvent e1, MotionEvent e2, float dx, float dy)
  173. {
  174. float ax = 0;
  175. float ay = 0;
  176.  
  177. ax = (dx / this.scale) / 0.2f; // Distance to the centre in metres
  178. ay = (dy / this.scale) / 0.2f;
  179.  
  180. this.centrum = new PointF(centrum.X + ax, centrum.Y - ay);
  181. this.Invalidate();
  182. return (true);
  183. }
  184.  
  185. public void OnShowPress(MotionEvent e)
  186. {
  187. }
  188.  
  189. public bool OnSingleTapUp(MotionEvent e)
  190. {
  191. return true;
  192. }
  193.  
  194. public bool OnScale(ScaleGestureDetector detector)
  195. {
  196. this.scale *= detector.ScaleFactor;
  197. this.Invalidate();
  198. return true;
  199. }
  200.  
  201. public bool OnScaleBegin(ScaleGestureDetector detector)
  202. {
  203. return true;
  204. }
  205.  
  206. public void OnScaleEnd(ScaleGestureDetector detector)
  207. {
  208. }
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement