![Page 1: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/1.jpg)
1 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
dr Artur Bartoszewski
![Page 2: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/2.jpg)
2 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
![Page 3: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/3.jpg)
3 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Do obsługi gestów w API Androida służy obiekt GestureDetector
GestureDetector nazwa = new GestureDetector(kontekst, słuchacz);
GestureDetector posiada interfejs OnGestureListener, który
implementuje metody odpowiedzialne za rozpoznawanie i obsługę
różnego rodzaju gestów.
![Page 4: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/4.jpg)
4 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Implementacja metod listenera
W tym przykładzie aktywność
MainActivity implementuje interfejs
GestureDetector.OnGestureListener.
Po zaimplementowaniu interfejsu należy
uzupełnić aktywność o związane z nim
metody
![Page 5: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/5.jpg)
5 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Implementacja metod listenera
Interfejs OnGestureListener implementuje wewnątrz klasy MainActivity metody
obsługi gestów.
![Page 6: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/6.jpg)
6 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Dodawanie obiektu GestureDetector
Następnie w metodzie OnCreate tworzymy instancję słuchacza gestów –
instancję klasy GestureDetector
• Drugim parametrem jego konstruktora jest „this” – czyli prościej mówiąc
słuchaczem dla gestów staje się główna aktywność.
![Page 7: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/7.jpg)
7 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Przechwytywanie zdarzeń i przesyłanie do GestureDetector-a
Aby przechwycić zdarzenie gestu nadpisujemy metodę: onTouchEvent(..)
Otrzymuje ona w parametrze obiekt event typu MotionEwent opisujący gest.
Zdarzenie to przesyłamy do zdefiniowanego wcześniej słuchacza gestów za
pomocą metody onTouchEvent()
np.: detektorGestów.onTouchEvent(event)
![Page 8: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/8.jpg)
8 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Naciśnięcie ekranu - onDown
Obiekt „e” typu MotionEwent opisujący gest posiada metody, za pomocą
których odczytać możemy parametry gestu np.: .getX() .getY()
![Page 9: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/9.jpg)
9 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
„Tupnięcie” na ekran - onSingleTapUp
Obiekt „e” typu MotionEwent opisujący gest posiada metody, za pomocą
których odczytać możemy parametry gestu np.: .getX() .getY()
![Page 10: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/10.jpg)
10 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Krótkie naciśnięcie ekranu- onShowPress
Obiekt „e” typu MotionEwent opisujący gest posiada metody, za pomocą
których odczytać możemy parametry gestu np.: .getX() .getY()
![Page 11: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/11.jpg)
11 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Długie naciśnięcie ekranu- onLongPress
Obiekt „e” typu MotionEwent opisujący gest posiada metody, za pomocą
których odczytać możemy parametry gestu np.: .getX() .getY()
![Page 12: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/12.jpg)
12 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Przeciągnięcie po ekranie
Ges przeciągnięcia po ekranie generuje dwa zdarzenia:
onScrool - pozwala odczytać pozycję początku i końca
przeciągnięcia oraz jego dystans (w rozbiciu na dystans po osi
x oraz po osi y (prędkość gestu nie jest istotna)
onFiling – pozwala odczytać prędkość gestu – w rozbiciu na
prędkość poziomą i pionową
![Page 13: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/13.jpg)
13 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Przeciągnięcie po ekranie - onScroll
![Page 14: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/14.jpg)
14 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Przeciągnięcie po ekranie - onFiling
![Page 15: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/15.jpg)
15 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
![Page 16: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/16.jpg)
16 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Rodzaje logów
Log.v (..) - VERBOSE
Log.d (..) - DEBUG
Log.i (..) - INFO
Log.w (..) - WARN (warning)
Log.e (..) - ERROR
Logi debugowania są kompilowane, ale usuwane w czasie
wykonywania. Dzienniki Logi, ostrzeżeń i informacji są zawsze
przechowywane.
![Page 17: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/17.jpg)
17 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Tworzenie logów
Dla testu logi wygenerowano w metodzie onCreate
![Page 18: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/18.jpg)
18 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
Tworzenie logów
Logi wygenerowane przez kod z poprzedniego slajdu
![Page 19: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/19.jpg)
19 dr Artur Bartoszewski - Aplikacje mobilne - Wykład
Aplikacje mobilne
![Page 20: Slajd 1 - Radom...Title Slajd 1 Author Volfek Created Date 12/2/2019 7:34:37 PM](https://reader033.vdocuments.mx/reader033/viewer/2022050507/5f984093d46aaa22bd55587e/html5/thumbnails/20.jpg)
20
Literatura
dr Artur Bartoszewski - Aplikacje mobilne - Wykład