De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Resources. Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { } class KompasView :

Verwante presentaties


Presentatie over: "Resources. Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { } class KompasView :"— Transcript van de presentatie:

1 Resources

2 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

3 Layout Button protected override void OnCreate(Bundle b) { base.OnCreate(b); SeekBar rood = new SeekBar(this); } LayoutParams par; LinearLayout stapel; stapel = new LinearLayout(this); stapel.AddView(rood); stapel.AddView(grn); stapel.AddView(blw); this.SetContentView(stapel); grn = new SeekBar(this); blw = new SeekBar(this); par = new LayoutParams ( LayoutParams.MatchParent, 120 );, par );

4 Layout Button protected override void OnCreate(Bundle b) { base.OnCreate(b); SeekBar rood = new SeekBar(this); } LayoutParams par; LinearLayout stapel; stapel = new LinearLayout(this); stapel.AddView(rood); stapel.AddView(grn); stapel.AddView(blw); this.SetContentView(stapel); grn = new SeekBar(this); blw = new SeekBar(this); par = new LayoutParams ( LayoutParams.MatchParent, LayoutParmas.WrapContent );, par );, 0.25f

5 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

6 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;

7 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();

8 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);

9 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,...);

10 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... );

11 Gesture-detection 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?

12 Hoofdstuk 7 Herhaling Nieuw!

13 while ( x<1000 ) x = 2*x; public void OnDraw (Canvas canvas) { int x; x = 1; canvas. DrawString ( x.ToString(), 10, 10, verf); } Opdrachten herhalen body wordt steeds opnieuw uitgevoerd zolang de voorwaarde geldig is X12481632641282565121024

14 Meer opdrachten herhalen int x, t; x=1; t=0; while ( x<1000 ) { x = 2*x; t = t+1; } return t; } n private static int Naam ( ) { accolades smeden twee opdrachten tot één body teller telt hoe vaak er wordt verdubbeld (int n)TweeLog

15 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

16 Publieksvraag nSchrijf een methode driewerf met een String-parameter, die 3 herhalingen ervan oplevert nSchrijf een methode veelwerf met een String-parameter, en een getal n die n herhalingen van de String oplevert private string driewerf (string x) { } return x+x+x;

17 while ( t<n ) { t = t+1 ; } t = 0; private static string veelwerf (string x, int n) { Veelwerf-methode return result; result = result + x ; result = ""; int t; string result; }

18 Publieksvraag nMaak een methode macht met twee parameters ugrondtal (reëel getal) uexponent(natuurlijk getal) die de waarde oplevert van grondtal exponent

19 while ( t<n ) { t = t+1 ; } t = 0; private static double macht (double x, int n) { Machtsverhef-methode return result; result = result * x ; result = 1; int t; double result; }

20 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 ?

21 Expressies nExpressie met een getal als waarde nExpressie met een tekst als waarde nExpressie met een waarheid als waarde 2 * (lengte + breedte) "Hallo " + persoon teller < exponent type int type bool type string value object- value

22 Bool expressies nVergelijken van waarden nCombineren van andere bool-expressies met logische operatoren u&&and u||or u !not x <= y x 0 ! (x==0 && y==0)x!=0 || y!=0 George Boole (1815-1864)

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

24 Constanten nConstanten met een getal als waarde nConstanten met een tekst als waarde nConstanten met een waarheid als waarde 2 "Hallo" true -5137 "@#$%""123""" false "true"

25 Gebruik van bool expressies nAls voorwaarde van een while-opdracht nRechts van een toekenningsopdracht nAls resultaat van een methode while (x<10)... bool b; b = x<10 ; return x<10 ;

26 Publieksvraag nSchrijf een methode deelbaar, die antwoordt of x deelbaar is door d private static bool deelbaar (int x, int d) { } x%d == 0return ; waarheidswaarde als resultaat

27 Publieksvraag nSchrijf een methode kleinsteDeler, die antwoordt wat de kleinste deler is van x private static int kleinsteDeler (int x) { } int d; d = 2; while ( x%d != 0) d = d+1; return d ; probeer ze één voor één

28 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

29 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;

30 Syntax van opdrachten opdracht (), ;expressie klasse naam object expressie. methode naam =expressie;variabele property naam += returnexpressie; while)(expressieopdrachtblok for)(expropdrachtexpr ;;

31 Syntax van opdrachten opdracht returnexpressie; while)(expressieopdrachtblok for)(expropdrachtexpr ;;

32 Herhaalde herhaling nBody van een for-opdracht is een opdracht dat kan zelf ook een for-opdracht zijn! int x, y; for (y=0; y<10; y++) for (x=0; x<10; x++) c.DrawString( "+",, 10*x, 10*(y+1), verf); y + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

33 Extreme gevallen 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!

34 RGB-Kubus 3x RadioButton SeekBar KubusView 5x RadioButton

35 Kubus } { public 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;

36 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)


Download ppt "Resources. Kompas } { protected override void OnDraw(Canvas canv) { base.OnDraw(canv); } public KompasView(Context c) : base(c) { } class KompasView :"

Verwante presentaties


Ads door Google