Programma opdrachten methoden klasse variabelen en Geheugen objecten klasse zijn gegroepeerd in hebben als type veranderen bewerken.

Verwante presentaties


Presentatie over: "Programma opdrachten methoden klasse variabelen en Geheugen objecten klasse zijn gegroepeerd in hebben als type veranderen bewerken."— Transcript van de presentatie:

1 Programma opdrachten methoden klasse variabelen en Geheugen objecten klasse zijn gegroepeerd in hebben als type veranderen bewerken

2 Values versus Pointers Color c; Rect r; class Rect struct Color c 0 0 R G 0 B 255 10 30 Left Right 20 Top 40 Bottom c = new Color(255,0,0); new Rect(10,20,30,40); null r r =

3 Methoden met een resultaat private double kwadraat (double x) { return x*x ; } type van het resultaat waarde van het resultaat in speciale return-opdracht

4 Methoden met een resultaat nSchrijf methodes omtrek en diagonaal met een Rect als parameter, die dat uitrekenen public int omtrek (Rect r) { } return 2*(br+h); Left Top Right Bottom int br = r.Right-r.Left; int h = r.Bottom-r.Top; br h public double diagonaal(Rect r) { } return Math.Sqrt(a*a + b*b); int a = r.Right-r.Left; int b = r.Bottom-r.Top; a 2 + b 2 = c 2

5 Cirkel- klikker } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawCircle(p.X, p.Y, 50, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); if (p != null)

6 if-opdracht opdracht wordt alleen uitgevoerd als voorwaarde niet geldt if (temperatuur<0) uitvoer.Text = "Het vriest!”; else uitvoer.Text = "Het dooit."; opdracht wordt alleen uitgevoerd als voorwaarde geldt

7 Syntax van opdrachten opdracht (), ;expressie klasse naam object expressie. methode naam =expressie;variabele property naam += returnexpressie; if)(expressieopdrachtblok opdrachtelse

8 Cirkel- klikker } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); if (p != null) met bitmap b = BitmapFactory.DecodeResource (...Icon...); Bitmap b;

9 Punten- klikker } { protected override void OnDraw(Canvas c) { base.OnDraw(c); } public MijnView(Context c) : base(c) { this.Touch += raakAan; } class MijnView : View public void raakAan(object o, TouchEventArgs tea) { } } c.DrawBitmap(b, p.X, p.Y, new Paint()); x = tea.Event.GetX(); y = tea.Event.GetY(); this.Invalidate(); float x, y; PointF p; p = new PointF(x, y); foreach( PointF p in alles) met bitmap b = BitmapFactory.DecodeResource (...Icon...); Bitmap b; List alles = new List ( ) ; alles.Add(p);

10 Syntax van opdrachten opdracht (), ;expressie klasse naam object expressie. methode naam =expressie;variabele property naam += returnexpressie; if)(expressieopdrachtblok opdrachtelse typeexprinnaamforeach()opdracht

11 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { } class KompasView : View Bitmap b; canv.DrawBitmap(b, 0, 0, verf); BitmapFactory.Options opties = new BitmapFactory.Options(); opties. InScaled = false; b = BitmapFactory. DecodeResource ( ); c.Resources, Resource. Drawable. UU1024, opties

12 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { b = BitmapFactory.DecodeResource (...UU...); } class KompasView : View Bitmap b; canv.DrawBitmap(b, 0, 0, verf);

13 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { b = BitmapFactory.DecodeResource (...UU...); } class KompasView : View Bitmap b; canv.DrawBitmap(b, 0, 0, verf);

14 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { b = BitmapFactory.DecodeResource (...UU...); } class KompasView : View public void OnSensorChanged(SensorEvent s) { } Bitmap b;float Schaal;float Hoek;, ISensorListener canv.DrawBitmap(b, mat, verf); Schaal = this.Width / b.Width; Matrix mat = new Matrix(); mat.PostScale(Schaal, Schaal); mat.PostRotate(- Hoek); mat.PostTranslate(Width/2, Height/2); mat.PostTranslate(-b.Width/2, -b.Height/2); Hoek = s.Values[0]; this.Invalidate( ); SensorManager sm = c. GetSystemService(...); sm.RegisterListener(this,...Orientation... );

15 Interface nIn de library nIn je eigen programma interface ISensorListener { } public void OnSensorChanged(SensorEvent s); class KompasView : View { } public KompasView(Context c) : base(c) {...... } public OnDraw(Canvas c) {...... } public void OnSensorChanged(SensorEvent s) {...... }, ISensorListener wat is er nodig om een ISensorListener te zijn? deze methode! ik beloof een ISensorListener te zijn en implementeer dus de methode!

16 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { b = BitmapFactory.DecodeResource (...UU...); } class KompasView : View public void OnSensorChanged(SensorEvent s) { } Bitmap b;float Schaal;float Hoek;, ISensorListener canv.DrawBitmap(b, mat, verf); Schaal = this.Width / b.Width; Matrix mat = new Matrix(); mat.PostScale(Schaal, Schaal); mat.PostRotate(- Hoek); mat.PostTranslate(Width/2, Height/2); mat.PostTranslate(-b.Width/2, -b.Height/2); Hoek = s.Values[0]; this.Invalidate( ); SensorManager sm = c. GetSystemService(...); sm.RegisterListener(this,...Orientation... );

17 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { b = BitmapFactory.DecodeResource (...UU...); } class KompasView : View public void OnSensorChanged(SensorEvent s) { } Bitmap b;float Schaal;float Hoek;, ISensorListener canv.DrawBitmap(b, mat, verf); Schaal = this.Width / b.Width; Matrix mat = new Matrix(); mat.PostScale(Schaal, Schaal); mat.PostRotate(- Hoek); mat.PostTranslate(Width/2, Height/2); mat.PostTranslate(-b.Width/2, -b.Height/2); Hoek = s.Values[0]; this.Invalidate( ); SensorManager sm = c. GetSystemService(...); sm.RegisterListener(this,...Orientation... ); is een geldige ISensorListener want zijn klasse heeft deze methode

18 Gestures pinch nTouch uraak het scherm aan nDrag uverplaats iets nSwipe uveeg weg nPinch uknijp om te verkleinen

19 pinch- Kompas } { public void RaakAan( object o, TouchEventArgs tea ) { class KompasView : View Bitmap b;float Schaal;float Hoek;, ISensorListener v1=new PointF( tea...GetX(), tea...GetY() ); } v2=new PointF( tea...GetX(1), tea...GetY(1)); if (tea...PointerCount==2) { if (tea...Action==...Pointer2Down) { } float afst = afstand(v1, v2); float start = afstand(s1, s2); float factor = afst / start; this.Schaal = oudeSchaal * factor; this.Invalidate(); PointF v1, v2; PointF s1, s2; s1=v1; s2=v2; float oudeSchaal; oudeSchaal = Schaal; pinch

20 Gesture-detection pinch nTouch nDrag nSwipe nPinch nRotate nAlles tegelijk n3-vinger beweging niet zo moeilijk iets ingewikkelder erg lastig

21 Gestures

22 Gesture-detection pinch nTouch nDrag nSwipe nPinch nRotate nAlles tegelijk n3-vinger beweging njouw innovatieve gesture niet zo moeilijk iets ingewikkelder erg lastig laten herkennen door library toch zelf doen?

23 Gesture-detection pinch nTouch nDrag nSwipe nPinch nRotate nAlles tegelijk n3-vinger beweging niet zo moeilijk iets ingewikkelder erg lastig laten herkennen door library Hoe?

24 Kompas met Gesture detector { public void RaakAan(..., TouchEventArgs tea ) { class KompasView : View float Schaal; } this.Schaal = oSchaal * factor; this.Invalidate(); public KompasView(Context c) : base(c) {...... } this.Touch += RaakAan; public void OnDraw(Canvas canv) {......Schaal.........ingewikkeld gedoe...

25 Kompas met Gesture detector { public void RaakAan(..., TouchEventArgs tea ) { class KompasView : View float Schaal;, IOnScaleGestureListener } this.Schaal = oSchaal * factor; this.Invalidate(); public void OnScale(ScaleGestureDetector d) { } this.Schaal = Schaal * d.ScaleFactor; this.Invalidate(); public KompasView(Context c) : base(c) {...... } this.Touch += RaakAan; det = new ScaleGestureDetector(c, this); ScaleGestureDetector det; public void OnDraw(Canvas canv) {......Schaal.........ingewikkeld gedoe... det. OnTouchEvent ( tea ); krijgt een seintje als het zover is belooft te kunnen luisteren

26 SensorManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnSensorChanged(SensorEvent s) { }, ISensorListener this,......SensorType. Orientation... x = s.Values[0]; SensorManager sm =......; sm.RegisterListener (, SensorDelay.Ui ); } Temperature Pressure Light Proximity HeartRate Normal if (s.SensorType.Type==SensorType.Light) Location meet bijna alles Game

27 LocationManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnSensorChanged(SensorEvent s) { }, ISensorListener this,......SensorType. Orientation... x = s.Values[0]; SensorManager sm =......; sm.RegisterListener (, SensorDelay.Ui ); } if (s.SensorType.Type==SensorType.Light) meet GPS-positie

28 LocationManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnSensorChanged(SensorEvent s) { }, ISensorListener this,......SensorType. Orientation... x = s.Values[0]; LocationManager lm =......; lm.RequestLocationUpdates (, SensorDelay.Ui ); } if (s.SensorType.Type==SensorType.Light) meet GPS-positie

29 LocationManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnSensorChanged(SensorEvent s) { }, ISensorListener, this x = s.Values[0]; LocationManager lm =......; lm.RequestLocationUpdates ( ); } if (s.SensorType.Type==SensorType.Light) meet GPS-positie......

30 LocationManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnSensorChanged(SensorEvent s) { }, ILocationListener, this x = s.Values[0]; LocationManager lm =......; lm.RequestLocationUpdates ( ); } if (s.SensorType.Type==SensorType.Light) meet GPS-positie......

31 LocationManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnLocationChanged(Location loc) { }, ILocationListener, this x = s.Values[0]; LocationManager lm =......; lm.RequestLocationUpdates ( ); } meet GPS-positie......

32 LocationManager } { public MijnView(Context c) : base(c) { class MijnView : View public void OnLocationChanged(Location loc) { }, ILocationListener, this noord = loc.Latitude; oost = loc.Longitude; LocationManager lm =......; lm.RequestLocationUpdates ( ); } meet GPS-positie......

33 Practicumopgave: Running App

34 Running App n Knoppen n Statusregel n Kaart ugelopen track upositie met orientatie Brainstorm-idee: drag pinch

35 Kaartmateriaal CC-BY-4.0 licentie 10MB per blad

36 Kaartmateriaal op de practicumsite 1km = 400 pixels

37 Kaartprojectie o Geografisch nRD-kilometergrid public PointF Geo2RD ( PointF geo ) { return rd; } const double fi0 = 52.15517440; const double lam0 = 5.38720621; const double x0 = 155000.00; const double y0 = 463000.00; double fi = geo.X; double lam = geo.Y; double dFi = 0.36 * (fi - fi0); double dLam = 0.36 * (lam - lam0); double dFi2 = dFi * dFi; double dFi3 = dFi2 * dFi; double dLam2 = dLam * dLam; double dLam3 = dLam2 * dLam; double dLam4 = dLam3 * dLam; double x = x0 + 190094.945 * dLam - 11832.228 * dFi * dLam - 114.221 * dFi2 * dLam- 32.391 * dLam3 - 0.705 * dFi - 2.340 * dFi3 * dLam - 0.608 * dFi * dLam3 - 0.008 * dLam2 + 0.148 * dFi2 * dLam3; double y = y0 + 309056.544 * dFi + 3638.893 * dLam2 + 73.077 * dFi2 - 157.984 * dFi * dLam2 + 59.788 * dFi3 + 0.433 * dLam - 6.439 * dFi2 * dLam2 - 0.032 * dFi * dLam + 0.092 * dLam4 - 0.054 * dFi * dLam4; PointF rd = new PointF((float)x, (float)y); in graden in meters op de practicumsite


Download ppt "Programma opdrachten methoden klasse variabelen en Geheugen objecten klasse zijn gegroepeerd in hebben als type veranderen bewerken."

Verwante presentaties


Ads door Google