Linked Questions

Popular Questions

Animation not working with InterstitialAd

Asked by At

So I have always wanted to build games/apps and learned some xml years ago, grade 7 self taught, kinda lost ambition over the years, life what not. 2 weeks ago I started teaching myself java and I made a simple app spin the bottle. I have worked out most of the quarks but im stuck on this what am I doing wrong here. the app works perfect without the counter installed to pop up a interstitial ad but once I insert from "Button spin =(Button)" to "counter =1; }else {..." The animation of the bottle spinning stops. I have been looking over the web and trying different things I can think of for 2 days now and it's driving me crazy. Any help would be Greatly Appreciated Thanks in advance.

        Button spin =(Button) findViewById(R.id.button);
        ((Button) spin).setOnClickListener(new View.OnClickListener(){
            public void onClick(View view) {

                if (counter == 4) {
                    Log.i("log-", "INTERSTITIAL is loaded!");
                    if (mInterstitialAd.isLoaded()) {
                        mInterstitialAd.show();
                    }
                    counter = 1;
                }
                else {
                    counter++;
                }
            }
        });
    }



    public void spin(View v) {
            float newDirection = random.nextInt(3600);
            float pivoitX = imageView.getWidth() / 2;
            float pivoitY = imageView.getHeight() / 2;
            if (Math.abs(lastDirection - newDirection) < 360) {
                newDirection = lastDirection + newDirection + 360;
            }

            Animation rotate = new RotateAnimation(lastDirection, newDirection, pivoitX, pivoitY);

            rotate.setDuration(2000);
            rotate.setFillAfter(true);
            rotate.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    button.setEnabled(false);
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    button.setEnabled(true);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }


            });
            lastDirection = newDirection;
            imageView.startAnimation(rotate);

        }

Related Questions