Mueckenfang App handler Problem

  • 14 Antworten
  • Letztes Antwortdatum
S

Speedy1985

Neues Mitglied
0
Guten Tag zusammen,

ich bin neu hier im Forum und habe mich angemeldet, weil ich einfach nicht mehr weiter weiß und hoffe auf eure Hilfe.

Im Buch "Android-Apps entwickeln" von Uwe Post, welches ja schon mehrfach für Forenbeiträge gesorgt hat, bin ich nun beim Mückenfang-Projekt zumindest schon so weit, dass ich bei den Animationen angekommen bin, genauer gesagt beim Ausblenden der Mücke. Dabei heißt es, damit nicht gleichzeitig eine Mücke gezeichnet und entfernt wird, muss das eigentliche "Löschen" der Mücke an den handler übergeben werden. Das verstehe ich alles. Somit ist gewährleistet, dass nicht zwei Sachen gleichzeitig ablaufen, sondern schön nacheinander.

Dafür wird ein AnimationsListener erzeugt, der etwas ausführt, sobald die Animation beendet ist. Siehe Code:

Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] MueckeAnimationListener [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AnimationListener {[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]    private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] View [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]    public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] MueckeAnimationListener(View m) {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]       muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = m;[/SIZE]
[SIZE=2]   }[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]    public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onAnimationEnd(Animation animation) {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]       handler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[U]post[/U]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Runnable() {[/SIZE]
[SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]           @Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]              public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] run() {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]               spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].removeView([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2]           }[/SIZE]
[SIZE=2]       });[/SIZE]
[SIZE=2]    }[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]    @Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]     public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onAnimationRepeat(Animation animation) {[/SIZE]
[SIZE=2]    }[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]    @Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]     public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onAnimationStart(Animation animation) {[/SIZE]
[SIZE=2]    } [/SIZE][/LEFT]
[SIZE=2]}[/SIZE]

Uwe Post schreibt, um nicht noch eine innere Klasse mit Konstruktor erzeugen zu müssen, verschachtelt er das ganze zu einer anonymen inneren Klasse.

Leider gibt mir eclipse hier bei der handler.post(...-Anweisung eine Fehlermeldung aus:
The method post(Runnable) in the type Handler is not applicable for the arguments (new GameActivity.Runnable(){})

Was hat dies zu bedeuten?

Vielleicht habt ihr einen Tipp für mich!

Viele Grüße, Christian
 
Zuletzt bearbeitet:
Hi,

Du hast in GameActivity offenbar ein "Runnable" definiert, welches nun benutzt wird (GameActivity.Runnable).
Erwartet wird aber sicherlich java.lang.Runnable. Du kannst nun dir die imports mal ansehen, oder aber auch impliziet java.lang.Runnable vorgeben.

Code:
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]handler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[U]post[/U]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] java.lang.Runnable() {[/SIZE] 
     [SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055] 
      public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055] void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] run() {[/SIZE] 
         [SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].removeView([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][SIZE=2]
     }[/SIZE] 
[SIZE=2]});[/SIZE]
Ansonsten mußt Du uns mal den "handler" und vorallem die post Methode zeigen, da ist fest definiert, welche Argumente übergeben werden und welchen Typ diese haben müssen.
 
Zuletzt bearbeitet:
Hallo Khan!

vielen Dank, das war das Problem. Mit deinem Quelltext funktionierts wunderbar. Ganz verstehen tu ich allerdings noch nicht warum.

Bei den Imports steht bei mir keine Runnable dabei.
Bei einer anderen Klasse wurde die Runnable über implements mit eingebunden. Hast du das gemeint?

Die post-Methode habe ich nirgends im Quellcode. Muss ich auch nicht oder? Die sollte doch schon wissen, was sie zu tun hat oder nicht?

Vielen Dank nochmal!

Gruß Christian
 
Benutzt Du evtl. Eclipse?
Dann kannst Du mal auf die "post" Methode gehen (mit der Maus) und F3 drücken (open Deklaration). Dann springt Du direkt dorthin.

Das eigentliche Problem was Du hast ist ein Namenskonflikt. Es gibt zwei mal ein Interface Runnable. Einmal bei dir irgendwo im Projekt "GameActivity.Runnable" und einmal über java.lang.Runnable.
Bei java.lang muss man wissen, dass man dafür keine extra Imports braucht. Alle darin enthaltenen Klassen/Pakete sind impliziet immer dabei. So zum Beispiel auch java.lang.String.

Wenn dein Code zu Bytecode compiliert wird, muss sich der Compiler entscheiden, welches Runnable hat der Programmierer gemeint. Und der Compiler nimmt einfach das "nächste" und das ist nunmal das Interface in deinem Projekt.
Wenn Du nun aber im Code java.lang.Runnable schreibst, ist das ein vollqualifizierter Name und der Compiler weiß genau, dass er nur dieses Interface nehmen kann.
Du könntest auch das Interface in GameAcitivity.Runnable umbennen. Um Verwechselungen mit Standardklassen/Standardinterfaces zu vermeiden ist es sicherlich besonders für Anfänger einfacher eigene Namen zu verwenden.

Kannst uns ja mal dein GameActivity.Runnable zeigen, dann können wir nen schönen Namen überlegen. Sprechende Namen sind das A und O für gut lesbaren Code.


Der ursprüngliche Beitrag von 14:32 Uhr wurde um 14:36 Uhr ergänzt:

Die "post"-Methode ist in dem verwendeten "handler" drin. Leider kann ich nicht sehen welcher Handler das ist, weil die Deklaration/Initialisierung ([Typ] handler = new [Typ]();) aus deinem Codeschnippsel nicht hervor geht.
Wenn Du mir die Deklaration/Initialisierung und evtl. noch die Imports zeigst, kann ich dir genau sagen was bei dir im Code passiert.
Möglich wäre ja auch, dass der verwendete Handler von dir selbst geschrieben wurde, aber das würdest Du sicherlich wissen.
 
So ich hab hier mal die komplette Activity für euch.

Einen Handler habe ich selbst angelegt und Runnable bei der Klassendeklaration mit implementiert.

Ja ich benutze übrigens Eclipse als IDE.

Gruß Christian

Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]package[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] de.androidnewcomer.mueckenfang;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] java.util.Date;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] java.util.Random;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.app.Activity;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.app.Dialog;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.media.MediaPlayer;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.os.Bundle;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.os.Handler;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.Gravity;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.View;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.View.OnClickListener;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.ViewGroup.LayoutParams;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.animation.Animation;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.animation.Animation.AnimationListener;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.view.animation.AnimationUtils;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.FrameLayout;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.ImageView;[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]import[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] android.widget.TextView;
[/LEFT]
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] GameActivity [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnClickListener,Runnable {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ZEITSCHEIBEN[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 600;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]INTERVALL[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 100;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Random [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zufallsgenerator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Random();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Handler [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]handler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Handler();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] FrameLayout [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]punkte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gefangeneMuecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]float[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HOECHSTALTER_MS[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 2000;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MediaPlayer [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][I][U][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MUECKEN_BILDER[/I][/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][][] = {
{R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_nw[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_n[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_no[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]},
{R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_w[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_o[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]},
{R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_sw[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_s[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke_so[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]} };
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] String [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HIMMELSRICHTUNGEN[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][][] = {
{[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"nw"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"n"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"no"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]},
{[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"w"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]""[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"o"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] },
{[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"sw"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"s"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"so"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]} };

[/SIZE][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]game[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (FrameLayout) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = getResources().getDisplayMetrics().[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]density[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = MediaPlayer.[I]create[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.raw.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]summen[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
spielStarten();
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] spielStarten() {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0;
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]punkte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0;
starteRunde();
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] starteRunde() {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + 1;
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] * 10;
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gefangeneMuecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = 0;
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ZEITSCHEIBEN[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
bildschirmAktualisieren();
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]handler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].postDelayed([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]INTERVALL[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]boolean[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] pruefeRundenende() {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] == 0) {
starteRunde();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]boolean[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] pruefeSpielende() {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] == 0 && [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gefangeneMuecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] < [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) {
gameOver();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]return[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]false[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] gameOver() {

Dialog dialog = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Dialog([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], android.R.style.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]Theme_Translucent_NoTitleBar_Fullscreen[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
dialog.setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gameover[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
dialog.show();

}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] zeitHerunterzaehlen() {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] - 1;

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]float[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] zufallszahl = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zufallsgenerator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].nextFloat();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] wahrscheinlichkeit = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] * 1.5 / [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ZEITSCHEIBEN[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (wahrscheinlichkeit >1 ) {
eineMueckeAnzeigen();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (zufallszahl < wahrscheinlichkeit - 1) {
eineMueckeAnzeigen();
}
} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (zufallszahl < wahrscheinlichkeit) {
eineMueckeAnzeigen();
}
}
mueckenVerschwinden();
bildschirmAktualisieren();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](!pruefeSpielende()) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](!pruefeRundenende()) {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]handler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].postDelayed([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]INTERVALL[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}
}
mueckenBewegen();
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] bildschirmAktualisieren() {
TextView tvPunkte = (TextView) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]points[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
tvPunkte.setText([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Punkte: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + Integer.[I]toString[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]punkte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));

TextView tvRunde = (TextView) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]round[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
tvRunde.setText([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Runde: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + Integer.[I]toString[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));

TextView tvTreffer= (TextView) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]hits[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
tvTreffer.setText(Integer.[I]toString[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gefangeneMuecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));

TextView tvRestzeit = (TextView) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]time[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
tvRestzeit.setText(Integer.[I]toString[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));

FrameLayout flTreffer = (FrameLayout)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]bar_hits[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
LayoutParams lpTreffer = flTreffer.getLayoutParams();
lpTreffer.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]width[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = Math.[I]round[/I]( [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] * 300 * Math.[I]min[/I]( [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gefangeneMuecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) / [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] );

FrameLayout flZeit = (FrameLayout)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]bar_time[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
LayoutParams lpZeit = flZeit.getLayoutParams();
lpZeit.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]width[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = Math.[I]round[/I]( [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] * [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] * 300 / [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]ZEITSCHEIBEN[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] );
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] eineMueckeAnzeigen() {
FrameLayout spielbereich = (FrameLayout)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] breite = spielbereich.getWidth();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] hoehe = spielbereich.getHeight();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] muecke_breite = ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])Math.[I]round[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*50);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] muecke_hoehe = ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])Math.[I]round[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*42);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] links = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zufallsgenerator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].nextInt(breite-muecke_breite);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] oben = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zufallsgenerator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].nextInt(hoehe-muecke_hoehe);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vx;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vy;

ImageView muecke = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ImageView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
muecke.setTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]geburtsdatum[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Date());
muecke.setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);


FrameLayout.LayoutParams params = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] FrameLayout.LayoutParams(muecke_breite,muecke_hoehe);
params.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]leftMargin[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = links;
params.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]topMargin[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = oben;
params.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gravity[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= Gravity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]TOP[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + Gravity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LEFT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
spielbereich.addView(muecke,params);
muecke.setTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]geburtsdatum[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Date());

[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].seekTo(0);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].start();

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]do[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
vx = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zufallsgenerator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].nextInt(3)-1;
vy = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zufallsgenerator[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].nextInt(3)-1;
} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (vx == 0 && vy == 0);

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]double[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] faktor = 1.0;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](vx!=0 && vy !=0) {
faktor = 0.70710678;
}

setzeBild(muecke, vx, vy);

vx = ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) Math.[I]round[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*vx*faktor);
vy = ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) Math.[I]round[/I]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]massstab[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]*vy*faktor);

muecke.setTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]vx[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][U][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Integer(vx)[/U]);
muecke.setTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]vy[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][U][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Integer(vy)[/U]);
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mueckenVerschwinden() {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] nummer=0;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](nummer<[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getChildCount()) {
ImageView muecke = (ImageView) [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getChildAt(nummer);
Date geburtsdatum = (Date) muecke.getTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]geburtsdatum[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] alter = ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Date()).getTime() - geburtsdatum.getTime();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](alter > [/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HOECHSTALTER_MS[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].removeView(muecke);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].pause();
} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] { 
nummer++;
}
}
}

[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onClick(View muecke) {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](muecke.getAnimation()==[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]gefangeneMuecken[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]++;
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]punkte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] += 100;
bildschirmAktualisieren();
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].pause();
Animation animationTreffer = AnimationUtils.[I]loadAnimation[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.anim.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]treffer[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
muecke.startAnimation(animationTreffer);
animationTreffer.setAnimationListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MueckeAnimationListener(muecke));
}
}

[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] run() {
zeitHerunterzaehlen();
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]interface[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Runnable {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] run();
}

[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]protected[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onDestroy() {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mp[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].release();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onDestroy();
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MueckeAnimationListener [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] AnimationListener {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] View [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MueckeAnimationListener(View m) {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = m;
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onAnimationEnd(Animation animation) {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]handler[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].post([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] java.lang.Runnable() {
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] run() {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].removeView([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]muecke[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}
});
}

[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onAnimationRepeat(Animation animation) {
}

[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onAnimationStart(Animation animation) {
} 
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] mueckenBewegen() {
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (FrameLayout) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] nummer = 0;
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]( nummer < [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getChildCount()) {
ImageView muecke = (ImageView) [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spielbereich[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getChildAt(nummer);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vx = (Integer) muecke.getTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]vx[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vy = (Integer) muecke.getTag(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]vy[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
FrameLayout.LayoutParams params= (android.widget.FrameLayout.LayoutParams) muecke.getLayoutParams();
params.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]leftMargin[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] += vx*[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
params.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]topMargin[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] += vy*[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]runde[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
muecke.setLayoutParams(params);
nummer++;
}
}

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] setzeBild(ImageView muecke, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vx, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] vy) {
muecke.setImageResource(getResources().getIdentifier([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"muecke_"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]HIMMELSRICHTUNGEN[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][vy+1][vx+1], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"drawable"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getPackageName()));
}[/LEFT]
}
[/SIZE]
 
Dein interface Runnable kann - nein, muss - ersatzlos in die Tonne.

java.lang.Runnable != bla.mueckenfang.Runnable

Du kannst nicht einfach zwei Interface mit gleichem Namen nutzen und hoffen, dass Java die Klassen für austauschbar hält.
Das nennt man statisches Typsystem.
 
Zuletzt bearbeitet:
Hi,

um nochmal auf diesen Thread zurück zu kommen.
Wie bereits vermutet hast Du ein eignes "Runnable" Interface. Ich frage mich an der Stelle warum?
Dein Runnable entspricht praktisch dem Java-Standard Interface (java.lang.Runnable).
Ich halte dein Interface für unnötig (ist ja identisch). Du würdest ja auch nicht die Klasse String 1:1 nachprogrammieren, außer vielleicht zu Übungszwecken.

Dass das Interace "ersatzlos in die Tonne muss", wie es DieGoldeneMitte sagt, stimmt nicht. Die gleichen Bezeichner zu wählen ist unschön, weil es schwierig zu lesen ist. Ein Java-Entwickler liest "Runnable" und denkt sofort, dass es sich dabei um das "gewohnte" Interface handelt. Ein eigner Name ist daher schön, aber eben kein MUSS. Man kann auch mit voll qualifizierten Namen arbeiten, wie ich es dir bereits gezeigt habe (java.lang.Runnable) und der Compiler weiß genau was Du meinst.
 
Hi,

das hab ich so abgetippt, weils im Buch so drinsteht. Vielleicht, war es aber auch nur zum besseren Verständnis abgedruckt und ich habs dummerweise einfach abgeschrieben. Zu dem Zeitpunkt konnte ich noch nicht selbst nachvollziehen, wie das mit diesem Interface funktioniert.

Ich versuche mal zusammenzufassen:

Mein Interface Runnable mit der run()-Methode ist unsinn, da diese Funktion bereits im Klassenkopf implementiert ist.
Ich habe dadurch ein eigenes Interface gebastelt, welches irrsinnigerweise genauso heißt, wie das Original.
Der Grundgedanke des Runnable ist es, zu dem Zeitpunkt an dem es aufgerufen wird (wird es eigentlich explizit aufgerufen?) eine Anweisung an den Handler zu übergeben?

Gruß
Christian
 
Hi Speedy,

bist du eigentlich der Speedy der da mal nen Browsergame programmmiert hat (PHP) und öfter im IRC unterwegs war. Ok, trifft bestimmt auf 50% aller Entwickler zu, aber die hießen ja nicht alle Speedy.

Ein Interface (oder auch Schnittstelle) ist im Grunde eine Vorgabe bestimmte Methoden zu implementieren.
Wenn Du Runnable in deiner Klasse implementierst (public class Test implements java.lang.Runnable), dann verspricht deine Klasse sozusagen die run() Methode zur Verfügung zu stellen.
Warum man das macht?
Irgendwo gibt es eine Klasse die deine run-Methode aufruft. Einfach, weil Du versprochen hast Sie zu liefern, weiß der Compiler, weiß der Aufrufer, dass die Methode da ist. So kann eine externe Klasse deine run-Methode aufrufen obwohl diese externe Klasse natürlich nichts von deinem Code wissen kann, geschweige denn was er tut. Einzige dass die Methode da ist, dass steht fest.
Bei der aufrufenden Klasse steht dann nur noch soetwas wie:

Runnable someRunnable = ....
someRunnable.run();

Für die externe Klasse lieferst Du nämlich nur ein Runnable. Dein Klassenname wird dort natürlich nicht auftauchen.

Hoffe das war irgendwie verständlich.
 
Hallo Khan,

es wäre schön, aber ich glaube dieser Speedy, den du meinst, würde nicht solche Fragen stellen wie ich es tue.

Vielen Dank für die ausführliche Erklärung! Hat mich auf jeden Fall ein gutes Stück weiter gebracht, auch wenn ich mir dieses Kapitel noch genauer anschauen muss, um da ganz durchzusteigen...

Das Projekt Mückenfang ist fast komplett abgeschlossen. Leider hakts auf der Zielgeraden noch etwas. Ich muss etwas ausholen:

Man kann sich das Spiel als eine Art Moorhuhn vorstellen. Als Hintergrund wird mittlerweile das Vorschaubild der Kamera angezeigt. Das wurde gemacht, um später das Bild auf rote Objekte untersuchen zu können, denn Mücken hassen laut Buch Tomaten und sterben bei Berührung mit den gefährlichen Tomaten und geben doppelte Punktzahl... :smile:

Ich habe die beiden Activities, einmal für das Spiel ansich und einmal für die Kamera angehängt. Ich erwarte jetzt nicht, dass sich jeder den ganzen Quelltext zu Gemüte führt und überprüft, aber vielleicht besitzt jemand einen funktionierenden Quelltext und kann mir Tipps geben, wo es hängt.

Also zuerst die Game-Activity. Was ich auch nicht verstehe ist, dass mir eclipse bei der Deklaration (private CameraView cameraView;) das cameraView gelb unterringelt und empfielt, es zu löschen, da es nicht verwendet wird, obwohl ich in der onCreate-Methode das Kamera-Objekt verlinke...:unsure:

Code:
package de.androidnewcomer.mueckenfang;
import java.util.Date;
import java.util.Random;
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.Rect;
import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
public class GameActivity extends Activity implements OnClickListener,Runnable, PreviewCallback {
 
 private static final int ZEITSCHEIBEN = 600;
 private static final int INTERVALL = 100;
 private Random zufallsgenerator = new Random();
 private Handler handler = new Handler();
 private FrameLayout spielbereich;
 private int runde;
 private int punkte;
 private int muecken;
 private int gefangeneMuecken;
 private int zeit;
 private float massstab;
 private static final long HOECHSTALTER_MS = 2000;
 private MediaPlayer mp;
 private int schwierigkeitsgrad;
 private static final String HIMMELSRICHTUNGEN[][] = {
  {"nw", "n", "no"},
  {"w",  "",  "o" },
  {"sw", "s", "so"} };
 private CameraView cameraView;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        schwierigkeitsgrad = getIntent().getIntExtra("schwierigkeitsgrad", 0);
        setContentView(R.layout.game);
        cameraView = (CameraView) findViewById(R.id.camera);
        spielbereich = (FrameLayout) findViewById(R.id.spielbereich);
        massstab = getResources().getDisplayMetrics().density;
        mp = MediaPlayer.create(this, R.raw.summen);
        spielStarten();
    }
 
 private void spielStarten() {
  runde = 0;
  punkte = 0;
  starteRunde();
 }
 
 private void starteRunde() {
  runde = runde + 1;
  muecken = runde * (20 + schwierigkeitsgrad * 10);
  gefangeneMuecken = 0;
  zeit = ZEITSCHEIBEN;
  bildschirmAktualisieren();
        handler.postDelayed(this,INTERVALL);
 }
 private boolean pruefeRundenende() {
  if (zeit == 0) {
   starteRunde();
   return true;
  }
  return false;
 }
 private boolean pruefeSpielende() {
  if (zeit == 0 && gefangeneMuecken < muecken) {
   gameOver();
   return true;
  }
  return false;
 }
 private void gameOver() {
 
  setResult(punkte);
  Dialog dialog = new Dialog(this, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
  dialog.setContentView(R.layout.gameover);
  dialog.show();
 
 }
 private void zeitHerunterzaehlen() {
  zeit = zeit - 1;
 
  float zufallszahl = zufallsgenerator.nextFloat();
  double wahrscheinlichkeit = muecken * 1.5 / ZEITSCHEIBEN;
  if (wahrscheinlichkeit >1 ) {
   eineMueckeAnzeigen();
   if (zufallszahl < wahrscheinlichkeit - 1) {
    eineMueckeAnzeigen();
   }
  } else {
   if (zufallszahl < wahrscheinlichkeit) {
    eineMueckeAnzeigen();
   }
  }
  mueckenVerschwinden();
  bildschirmAktualisieren();
  if(!pruefeSpielende()) {
        if(!pruefeRundenende()) {
         handler.postDelayed(this, INTERVALL);
        }
     }
  mueckenBewegen();
 }
    private void bildschirmAktualisieren() {
  TextView tvPunkte = (TextView) findViewById(R.id.points);
  tvPunkte.setText("Punkte: " + Integer.toString(punkte));
 
  TextView tvRunde = (TextView) findViewById(R.id.round);
  tvRunde.setText("Runde: " + Integer.toString(runde));
 
  TextView tvTreffer= (TextView) findViewById(R.id.hits);
  tvTreffer.setText(Integer.toString(gefangeneMuecken));
 
  TextView tvRestzeit = (TextView) findViewById(R.id.time);
  tvRestzeit.setText(Integer.toString(zeit));
 
  FrameLayout flTreffer = (FrameLayout)findViewById(R.id.bar_hits);
  LayoutParams lpTreffer = flTreffer.getLayoutParams();
  lpTreffer.width = Math.round( massstab * 300 * Math.min( gefangeneMuecken,muecken) / muecken );
 
  FrameLayout flZeit = (FrameLayout)findViewById(R.id.bar_time);
  LayoutParams lpZeit = flZeit.getLayoutParams();
  lpZeit.width = Math.round( massstab * zeit * 300 / ZEITSCHEIBEN );
 }
 private void eineMueckeAnzeigen() {
  FrameLayout spielbereich = (FrameLayout)findViewById(R.id.spielbereich);
 
     int breite = spielbereich.getWidth();
     int hoehe = spielbereich.getHeight();
     int muecke_breite = (int)Math.round(massstab*50);
  int muecke_hoehe = (int)Math.round(massstab*42);
     int links = zufallsgenerator.nextInt(breite-muecke_breite);
     int oben = zufallsgenerator.nextInt(hoehe-muecke_hoehe);
     int vx;
     int vy;
     ImageView muecke = new ImageView(this);
     muecke.setTag(R.id.geburtsdatum, new Date());
     muecke.setOnClickListener(this);
 
     FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(muecke_breite,muecke_hoehe);
  params.leftMargin = links;
  params.topMargin = oben;
     params.gravity= Gravity.TOP + Gravity.LEFT;
     spielbereich.addView(muecke,params);
     muecke.setTag(R.id.geburtsdatum, new Date());
 
     mp.seekTo(0);
     mp.start();
 
     do {
      vx = zufallsgenerator.nextInt(3)-1;
      vy = zufallsgenerator.nextInt(3)-1;
     } while (vx == 0 && vy == 0);
 
     double faktor = 1.0;
     if(vx!=0 && vy !=0) {
      faktor = 0.70710678;
     }
 
     setzeBild(muecke, vx, vy);
 
     vx = (int) Math.round(massstab*vx*faktor);
     vy = (int) Math.round(massstab*vy*faktor);
 
     muecke.setTag(R.id.vx, new Integer(vx));
     muecke.setTag(R.id.vy, new Integer(vy));
    }
 
    private void mueckenVerschwinden() {
 
     int nummer=0;
     while(nummer<spielbereich.getChildCount()) {
      ImageView muecke = (ImageView) spielbereich.getChildAt(nummer);
      Date geburtsdatum = (Date) muecke.getTag(R.id.geburtsdatum);
      long alter = (new Date()).getTime() - geburtsdatum.getTime();
      if(alter > HOECHSTALTER_MS) {
       spielbereich.removeView(muecke);
       mp.pause();
   } else { 
       nummer++;
      }
     }
    }
 @Override
 public void onClick(View muecke) {
 
  if(muecke.getAnimation()==null) {
   gefangeneMuecken++;
   punkte += 100 + schwierigkeitsgrad * 100;
   bildschirmAktualisieren();
   mp.pause();
   Animation animationTreffer = AnimationUtils.loadAnimation(this, R.anim.treffer);
   muecke.startAnimation(animationTreffer);
   animationTreffer.setAnimationListener(new MueckeAnimationListener(muecke));
  }
 }
 
 @Override
 public void run() {
  zeitHerunterzaehlen();
 }
 @Override
 protected void onDestroy() {
  mp.release();
  super.onDestroy();
 }
 
 private class MueckeAnimationListener implements AnimationListener {
 
  private View muecke;
  public MueckeAnimationListener(View m) {
   muecke = m;
  }
 
  public void onAnimationEnd(Animation animation) {
   handler.post(new java.lang.Runnable() {
    @Override
    public void run() {
     spielbereich.removeView(muecke);
    }
   });
  }
 
  @Override
  public void onAnimationRepeat(Animation animation) {
  }
 
  @Override
  public void onAnimationStart(Animation animation) {
  }  
 }
 
 private void mueckenBewegen() {
  spielbereich = (FrameLayout) findViewById(R.id.spielbereich);
  int nummer = 0;
  while( nummer < spielbereich.getChildCount()) {
   ImageView muecke = (ImageView) spielbereich.getChildAt(nummer);
   int vx = (Integer) muecke.getTag(R.id.vx);
   int vy = (Integer) muecke.getTag(R.id.vy);
   FrameLayout.LayoutParams params= (android.widget.FrameLayout.LayoutParams) muecke.getLayoutParams();
   params.leftMargin += vx*runde;
   params.topMargin += vy*runde;
   muecke.setLayoutParams(params);
   nummer++;
  }
 }
 
 private void setzeBild(ImageView muecke, int vx, int vy) {
  muecke.setImageResource(getResources().getIdentifier("muecke_"+HIMMELSRICHTUNGEN[vy+1][vx+1], "drawable", this.getPackageName()));
 }
 
 @Override
 public void onPreviewFrame(byte[] bild, Camera camera) {
  int breite = camera.getParameters().getPreviewSize().width;
  int hoehe = camera.getParameters().getPreviewSize().height;
 
  if (camera.getParameters().getPreviewFormat() == ImageFormat.NV21) {
   mueckenAufTomatenPruefen(bild, breite, hoehe);
  }
 }
 
 private void mueckenAufTomatenPruefen(byte[] bild, int breite, int hoehe) {
  int nummer = 0;
  while(nummer < spielbereich.getChildCount())
  {
   ImageView muecke = (ImageView) spielbereich.getChildAt(nummer);
   if(mueckeBeruehrtTomate(muecke, bild, breite, hoehe))
   {
    mp.pause();
    gefangeneMuecken++;
    punkte += 100 + schwierigkeitsgrad * 100;
    bildschirmAktualisieren();
    spielbereich.removeView(muecke);
   } else {
    nummer++;
   }
  }
 }
 private boolean mueckeBeruehrtTomate(ImageView muecke, byte[] bild,
   int breite, int hoehe) {
  float faktorHorizontal = hoehe * 1.0f / getResources().getDisplayMetrics().widthPixels;
  float faktorVertikal = breite * 1.0f / getResources().getDisplayMetrics().heightPixels;
  Rect ausschnitt = new Rect();
  ausschnitt.bottom = Math.round(hoehe - faktorHorizontal * muecke.getLeft());
  ausschnitt.top    = Math.round(hoehe - faktorHorizontal * muecke.getRight());
  ausschnitt.right  = Math.round(faktorVertikal * muecke.getBottom());
  ausschnitt.left   = Math.round(faktorVertikal * muecke.getTop());
  int rotePixel = zaehleRotePixel(bild, breite, hoehe, ausschnitt);
  if(rotePixel > 10)
  {
   return true;
  }
  return false;
 }
 private int holePixel ( byte[] bild, int breite, int hoehe, int x, int y )
 {
  if ( x>=breite || x<0 || y>=hoehe || y<0 ) return 0;
  int frameSize = breite * hoehe;
  int uvp = frameSize + (y >> 1) * breite;
  int Y = (0xff & ((int) bild[breite*y + x])) - 16;
  if (Y < 0) Y = 0;
  int v = (0xff & bild[uvp+2*(x/2)]) - 128;
  int u = (0xff & bild[uvp+2*(x/2)+1]) - 128;
  int y1192 = 1192 * Y;
  int r = (y1192 + 1634 * v);
  int g = (y1192 - 833 * v - 400 * u);
  int b = (y1192 + 2066 * u);
  if (r < 0) r = 0; else if (r > 262143) r = 262143;
  if (g < 0) g = 0; else if (g > 262143) g = 262143;
  if (b < 0) b = 0; else if (b > 262143) b = 262143;
  return 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff);
 }
 
 private int zaehleRotePixel(byte[] bild, int breite, int hoehe, Rect ausschnitt) {
  int anzahl = 0;
  for ( int x = ausschnitt.left; x < ausschnitt.right; x++ ) {
   for ( int y = ausschnitt.top; y < ausschnitt.bottom; y++) {
    if ( istPixelRot(bild, breite, hoehe, x, y) ) {
     anzahl++;
    }
   }
  }
  return anzahl;
 }
 
 private boolean istPixelRot (byte[] bild, int breite, int hoehe, int x, int y)
 {
  int farbe = holePixel(bild, breite, hoehe, x, y);
  return Color.red(farbe)-(Color.red(farbe)+Color.green(farbe)+Color.blue(farbe))/3 > 60;
 }
}

und abschließend die Kamera-Activity

Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]package
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]de.androidnewcomer.mueckenfang;[/SIZE]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]java.io.IOException;[/SIZE]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.content.Context;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.hardware.Camera;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.hardware.Camera.PreviewCallback;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.util.AttributeSet;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.util.Log;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.SurfaceHolder;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.SurfaceView;[/SIZE]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CameraView [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SurfaceView [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SurfaceHolder.Callback {[/SIZE]
 
[LEFT][SIZE=2]SurfaceHolder [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]Camera [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] surfaceChanged(SurfaceHolder holder, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] format, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] w, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] h) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE]
[SIZE=2]Camera.Parameters parameters = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getParameters();[/SIZE]
[SIZE=2]parameters.setPreviewSize(w, h);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setParameters(parameters);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].startPreview();[/SIZE]
[SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Exception e) {[/SIZE]
[SIZE=2]Log.[I]w[/I]([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"CameraView"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Exception"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], e);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] surfaceCreated(SurfaceHolder holder) {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = Camera.[I]open[/I]();[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setDisplayOrientation(90);[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setPreviewDisplay(holder);[/SIZE]
[SIZE=2]} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (IOException exception) {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].release();[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2];[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] surfaceDestroyed(SurfaceHolder holder) {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].stopPreview();[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].release();[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]; [/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CameraView(Context context, AttributeSet attrs) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](context, attrs);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = getHolder();[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].addCallback([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setType(SurfaceHolder.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SURFACE_TYPE_PUSH_BUFFERS[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] CameraView(Context context) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2](context);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = getHolder();[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].addCallback([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]surfaceHolder[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setType(SurfaceHolder.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]SURFACE_TYPE_PUSH_BUFFERS[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] setOneShotPreviewCallback(PreviewCallback callback) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ( [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] != [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ) {[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]camera[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOneShotPreviewCallback(callback);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
 
Hi,

"cameraView" wird von Eclipse unterstrichen weil es nur eine Zuweisung gibt, aber keinen Zugriff darauf.
 
Achso, dachte die Zuweisung wäre schon eine "Benutzung". Ok dann geht mein Problem vielleicht in diese Richtung...

Muss ich mal schauen. Danke schonmal!

Gruß Christian
 
hallo, ich bins mal wieder...

hab den bzw. die Fehler gefunden. In dem Quelltext auf der Buch CD ist die cameraView einige Male benutzt worden. Unter anderem, dass man die Zeile: cameraView.setOneShotPreviewCallback(this); in die Methode zum Herunterzählen der Zeit einfügen muss. Das steht leider nicht im Buch beschrieben. Denke an dieser Zeile ist es gelegen. Jetzt funktioniert alles wie gewünscht. ... naja fast.

Das spiel stürzt an manchen Stellen ab, z. B. wenn ich während das Spiel noch läuft die Zurück-Taste am Handy rechts unten drücke.

Ich habe schon ein paar Mal den Begriff LogCat gelesen, welches in Eclipse die ganzen Aktionen dokumentiert. Kann ich dem irgendwie sagen, wann er die Aufzeichnung beginnen und enden soll. Der nimmt ja hunderte Zeilen auf, auch bevor das Spiel gestartet wird. Das ist mir ehrlich gesagt etwas zu undurchsichtig. Oder vielleicht fehlen mir auch die richtigen Kniffe damit umzugehen.

Würde mich diesbezüglich über Kommentare freuen!

Gruß Christian
 
Hallo zusammen,

leider gabs auf meinen letzten Post noch keine Reaktionen, deshalb will ich etwas gezielter fragen, nachdem ich mich etwas näher mit dem LocCat befasst habe.

Ich weiß nun, dass ich über Filter nur Loggings, welche meine App betreffen filtern kann. Ich habe aber das Problem, dass in der Spalte Application der Name meiner App gar nicht angezeigt wird. Also kann ich auch nicht danach filtern. Mache ich was falsch? :confused2:

Gruß Christian
 
Du benutzt Eclipse?

Beim LogCat-Fenster kann man Filter hinzufügen (grünes Plus-Zeichen bei Saved Filters).
Dort bei "by Application Name:" deinen Applikationsnamen eintragen.
Den findest Du in deiner bin/AndroidManifest.xml

In meinem Fall steht dort:
<application
android:label="@string/app_name" >


Und die Strings sind festgelegt in der Datei res/values/strings.xml

Der Applikationsname steht übrigens auch an der App auf deinem Android.
Man kann auch nur Teile vom Namen benutzen, habe ich grad probiert.
 

Ähnliche Themen

G
Antworten
0
Aufrufe
153
Gerdchen07
G
G
Antworten
1
Aufrufe
396
Gerdchen07
G
G
Antworten
13
Aufrufe
628
Gerdchen07
G
L
Antworten
3
Aufrufe
689
mips400
mips400
migi01
Antworten
26
Aufrufe
2.048
migi01
migi01
Zurück
Oben Unten