De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Aangepaste timing nTheorie (16 colleges + 2 deeltentamens) nPraktijk (16 keer, 2 inleveropdrachten) college Tent. 1 Tent. 2 college prakt. 1 prakt. 2 prakt.

Verwante presentaties


Presentatie over: "Aangepaste timing nTheorie (16 colleges + 2 deeltentamens) nPraktijk (16 keer, 2 inleveropdrachten) college Tent. 1 Tent. 2 college prakt. 1 prakt. 2 prakt."— Transcript van de presentatie:

1 Aangepaste timing nTheorie (16 colleges + 2 deeltentamens) nPraktijk (16 keer, 2 inleveropdrachten) college Tent. 1 Tent. 2 college prakt. 1 prakt. 2 prakt. prakt. 1 prakt. prakt. 1 prakt. 2 werkcoll nOefening (4 werkcolleges) college prakt. 2 werkcoll collegeprakt. prakt. 1 prakt. 2 prakt. prakt. 1

2 Keuze / Herhaling opdracht wordt steeds opnieuw uitgevoerd zolang voorwaarde geldt while (temperatuur<0) temperatuur += 5; 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

3 Herhalen met een teller public void OnDraw (Canvas canvas) { int t; t=0; while ( t<10 ) { canvas.DrawString( ":-)", 0, 20*t, verf ); t = t+1; } teller bepaalt het aantal herhalingen en komt goed van pas in de body

4 while ( t<n ) { t = t+1 ; } t = 0; private static string veelwerf (string x, int n) { String verveelvoudigen return result; result = result + x ; result = ""; int t; string result; }

5 for( t=0; t<n; t++ ) private static string veelwerf (string x, int n) { String verveelvoudigen return result; result = result + x ; result = ""; int t; string result; }

6 Herhaling met een teller int t ; t = 0; while ( t<x ) t ++ ; } { // doe iets nuttigs // met t for ( t=0 ; t<x ; t++ ) for t ++ ; t = 0;

7 Vergelijk-operatoren n<kleiner dan n<=kleiner dan of gelijk aan n>groter dan n>=groter dan of gelijk aan n==gelijk aan n!=ongelijk aan x=5 x wordt 5 ! x==5 is x gelijk aan 5 ?

8 Kubus } { public override void OnCreate(Bundle b) { base.Oncreate(b); class KubusApp : Activity RadioButton r, g, b;SeekBar s;KubusView kv; } kv = new KubusView(this); SetContentView( kv ); s = new SeekBar(this); LinearLayout lay = new LinearLayout(this); lay.AddView(s); lay.AddView(kv); lay.AddView(grp); RadioGroup grp = new RadioGroup(this); grp.AddView(r); grp.AddView(g); grp.AddView(b); RadioButton r = new RadioButton(this); RadioButton g = new RadioButton(this); RadioButton b = new RadioButton(this); lay r.Click += kies; g.Click += kies; b.Click += kies; s.ProgressChanged+=pc;

9 Kubus } { public override void OnCreate(Bundle b) { base.Oncreate(b);......... class KubusApp : Activity RadioButton r, g, b;SeekBar s;KubusView kv; } r.Click += kies; g.Click += kies; b.Click += kies; s.ProgressChanged+=pc; public void kies(object o, EventArgs ea) { if (o==r) kv.Dim = 0; if (o==g) kv.Dim = 1; if (o==b) kv.Dim = 2; kv.Invalidate(); } public void kies(object o, EventArgs ea) { kv.Pos = s.Progress; } kv.Invalidate();

10 Kubus } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); public KubusView(Context c) : base(c) { } class KubusView: View public int Pos=0, Dim=2; int a = 16; float v = 255/(a-1); int d = Math.Min(Width, Height) / a; Paint verf = new Paint(); canv.DrawRect ( verf.Color = new Color( for (int y=0; y<a; y++) { } for (int x=0; x<a; x++) { v*x, v*y, Pos); d*x, d*y, d*(x+1), d*(y+1), verf); } } if (Dim==2)

11 Variabelen aanpassen nAfgekorte notaties: x = x * 2 ; oude waarde wordt nieuwe waarde x = x * 2 ; x *= 2 ; x = x + 5 ; x += 5 ; x = x + 1 ; x += 1 ; x ++ ; wordt vermenigvuldigd met wordt vermeerderd met wordt opgehoogd

12 Voorbeeld: Rente- berekening door de gebruiker in te vullen EditText -objecten TextView met het resultaat Button met een Click handler

13 Resource designer <LinearLayout xmlns:p1= "http://schemas.android.com/apk/res/android" p1:orientation="vertical" p1:layout_width="match_parent" p1:layout_height="match_parent" p1:id="@+id/linearLayout1"> <TextView p1:text="Bedrag" p1:textAppearance="?android:attr/ textAppearanceMedium" p1:layout_width="match_parent" p1:layout_height="wrap_content" p1:id="@+id/textView1" /> <EditText p1:inputType="numberDecimal" p1:layout_width="match_parent" p1:layout_height="wrap_content" p1:id="@+id/bedragBox" /> class RenteApp: Activity { } SetContentView (Resource.Layout.Main); override void OnCreate(...) { } EditText bedrag; bedrag = FindViewById (Resource.Id.bedragBox);

14 Rente-programma private void bereken(object o, EventArgs ea) { } bedragBox.Textdouble.Parse( ) ;double bedrag = double rente = double.Parse( renteBox.Text ); for (int jaar=0; jaar<=10; jaar++) bedrag *= (1+0.01*rente); resultaat.Text += $"na {jaar} jaar {bedrag}\n"; { } resultaat.Text = "";

15 Exceptions Exception: nUitzonderlijke toestand die door een methode wordt opgeworpen nDe situatie moet door de aanroeper van de methode worden opgevangen throw catch

16 Voorbeeld van Exception s = invoer. Text; n = int. Parse (s); uitvoer. Text = ( "kwadraat is " + n*n ); try { } catch ( Exception e ) { uitvoer. Text = ( s + " is geen getal" ); } kan een Exception opwerpen opvangen van het probleem

17 Meerdere catch-delen s = invoer. Text; n = int. Parse (s); uitvoer. Text = ( "kwadraat is " + n*n ); try { } catch ( FormatException e ) { uitvoer. Text = ( s + " is geen getal" ); } catch ( OverflowException e ) { uitvoer. Text = ( s + " is te groot" ); } als er een Exception optreedt, wordt de eerste catch gekozen met een passend type

18 Syntax van opdrachten opdracht (), ;expressie klasse naam object expressie. methode naam =expressie;variabele property naam += returnexpressie;

19 opdracht for)(expropdrachtexpr ;;,, declaratie typeexprinnaamforeach()opdracht var tryblokcatch(bloknaam)type while)(expressieopdracht if)(expressieopdracht elseopdracht returnexpressie; blok

20 Speciale gevallen van herhaling nNul keer herhalen for (y=0; y<0; y++) c.DrawString("hoi", 10, 10, verf); nOneindig vaak herhalen while (true) audio.Play( ); c.DrawString("hoi", 10, 10, verf); deze opdracht komt nooit aan de beurt!

21 Onbedoelde oneindigheid x=1; aantal = 0; while (aantal<10) x = x*2; aantal = aantal+1; {}{} accolades vergeten...

22 Onbedoelde oneindigheid for (x=0; totaal<100; x++) ; totaal = totaal + x ; Puntkomma teveel… ;

23 Running App n Knoppen n Statusregel n Kaart ugelopen track upositie met orientatie Onderdelen: drag pinch

24 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;, ISensorEventListener 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 ISensorEventListener want zijn klasse heeft deze methode belooft methodes

25 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;float Schaal;float Hoek; 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); LocationManager lm = c. GetSystemService(...); lm.RequestLocationUpdates(..., this); is een geldige ILocationListener want zijn klasse heeft deze methode belooft methodes, ILocationListener public void OnLocationChanged(Location loc) { } noord = loc.Latitude; oost = loc.Longitude;

26 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;float Schaal;float Hoek; 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); is een geldige IOnScaleGestureListener want zijn klasse heeft deze methode belooft methodes, IOnScaleGestureListener det = new ScaleGestureDetector(c, this); ScaleGestureDetector det; public void OnScale(ScaleGestureDetector d) { } this.Schaal = Schaal * d.ScaleFactor; this.Invalidate();

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

28 Interface nIn de library interface ISensorEventListener { } public void OnSensorChanged(SensorEvent s); wat is er nodig om een ISensorEventListener te zijn? deze methode! public void OnAccuracyChanged(SensorEvent s); interface ILocationListener { } public void OnLocationChanged(Location loc); public void OnProviderDisabled(string s); public void OnProviderEnabled(string s); public void OnStatusChanged(string s,...);

29 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;, ISensorEventListener 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... ); pixel van het plaatje dat in het midden moet komen

30 Kaart PointF centrum = new PointF(138300, 454300); 1km = 400 pixels 138300 meter 2300 meter 920 pixels midx = (centrum.X – 136000) * 0.4;

31 Kaart PointF centrum = new PointF(138300, 454300); 1km = 400 pixels 454300 meter 1300 m 1480 pixels midx = (centrum.X – 136000) * 0.4; midy = – (centrum.Y – 458000) * 0.4;

32 Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } class KompasView : View Bitmap b;float Schaal;float Hoek;, ISensorEventListener 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); pixel van het plaatje dat in het midden moet komen

33 Kaart } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } class KaartView : View Bitmap b;float Schaal;float Hoek;, ISensorEventListener canv.DrawBitmap(b, mat, verf); Matrix mat = new Matrix(); mat.PostScale(Schaal, Schaal); mat.PostTranslate(Width/2, Height/2); mat.PostTranslate(–midx, –midy); pixel van het plaatje dat in het midden moet komen

34 Coordinaten geografische coordinaten (graden) RD-projectie coordinaten (meters) bitmap (pixels) scherm (geschaalde pixels) geo2rd* 0.4* schaal rd2geo/ 0.4/ schaal

35 Huidige positie tekenen geo2rd* 0.4* schaal PointF huidig; // in meters! public void OnLocationChanged(Location loc) { } huidig = geo2rd(loc.Latitude, loc.Longitude); this.Invalidate();

36 Huidige positie tekenen geo2rd* 0.4* schaal PointF huidig; // in meters! public void OnDraw(Canvas c) { float ax = huidig.X – centrum.X; bereken de afstand tot het centrum float px = ax * 0.4; in pixels... op het scherm... float sx = px * Schaal; float x = this.Width/2+sx; c.DrawCircle(x,...);

37 Draggen rd2geo/ 0.4/ schaal public void RaakAan(..., TouchEventArgs tea) { op het scherm... float x = tea.Event.GetX(); float sx = x – dragstartpunt.X; in pixels... float px = sx / Schaal; in meters... float ax = px / 0.4;centrum.X –= ax; PointF dragstartpunt; // in schermpixels!

38 pinch- Kompas } { public void RaakAan( object o, TouchEventArgs tea ) { class KompasView : View Bitmap b;float Schaal;float Hoek;, ISensorEventListener 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

39 pinch- Kaart } { public void RaakAan( object o, TouchEventArgs tea ) { class KaartView : View Bitmap b;float Schaal;float Hoek;, ISensorEventListener 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 else... bool pinching = false; pinching = true; else if (!pinching)...

40 Aangepaste timing nTheorie (16 colleges + 2 deeltentamens) nPraktijk (16 keer, 2 inleveropdrachten) college Tent. 1 Tent. 2 college prakt. 1 prakt. 2 prakt. prakt. 1 prakt. prakt. 1 prakt. 2 werkcoll nOefening (4 werkcolleges) college prakt. 2 werkcoll collegeprakt. prakt. 1 prakt. 2 prakt. prakt. 1


Download ppt "Aangepaste timing nTheorie (16 colleges + 2 deeltentamens) nPraktijk (16 keer, 2 inleveropdrachten) college Tent. 1 Tent. 2 college prakt. 1 prakt. 2 prakt."

Verwante presentaties


Ads door Google