Zamiana bitmap co sekundę

0

Witam
Dlaczego poniższy kod zamiast wyświetlać co sekundę nową bitmapę, wyświetla po 10 sekundach kilka bitmap nałożonych na siebie?

MyActivity.java

package com.example.kamil.towerdefense_v3;

import java.io.FileNotFoundException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class MyActivity extends Activity implements OnClickListener {
    ImageView chosenImageView;
    Button choosePicture;
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        chosenImageView = (ImageView) this.findViewById(R.id.ChosenImageView);
        choosePicture = (Button) this.findViewById(R.id.ChoosePictureButton);

        choosePicture.setOnClickListener(this);



        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        Bitmap bmp_01 = BitmapFactory.decodeResource(getResources(), R.drawable.java_01);

        Bitmap alteredBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());

        Canvas canvas = new Canvas(alteredBitmap);
        Paint paint = new Paint();
        canvas.drawBitmap(bmp, 0, 0, paint);
        ImageView alteredImageView = (ImageView) this.findViewById(R.id.AlteredImageView);
        alteredImageView.setImageBitmap(alteredBitmap);
        chosenImageView.setImageBitmap(bmp);

        long TimeC = 0;
        long TimeS = 0;

        int BT = 0;
        boolean BR = false;

        while (TimeS < 10*1000) {

            long Time = System.currentTimeMillis();

            if (TimeC > 1*1000){

                if (BT == 0) BT = 1;
                else if (BT == 1) BT = 0;

                BR = true;
                TimeC = 0;

            }

            if (BR == true){

                if (BT == 0)    bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
                else            bmp = BitmapFactory.decodeResource(getResources(), R.drawable.java_01);

                alteredBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());

                canvas = new Canvas(alteredBitmap);
                paint = new Paint();
                canvas.drawBitmap(bmp, 0, 0, paint);
                alteredImageView = (ImageView) this.findViewById(R.id.AlteredImageView);
                alteredImageView.setImageBitmap(alteredBitmap);
                chosenImageView.setImageBitmap(bmp);

                BR = false;

            }

            TimeC += System.currentTimeMillis() - Time;
            TimeS += System.currentTimeMillis() - Time;

        }

    }

    public void onClick(View v) {
        Intent choosePictureIntent = new Intent(Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        startActivityForResult(choosePictureIntent, 0);
    }

    protected void onActivityResult(int requestCode, int resultCode,
                                    Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
    }
}

activity_my.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Choose Picture" android:id="@+id/ChoosePictureButton"/>

    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ChosenImageView"></ImageView>
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/AlteredImageView"></ImageView>
</LinearLayout>
1

bo on create się robi i dopiero jak się zrobi (czyli Ci przeleci cała pętla while) to wyświetla Ci wynik.

Stwórz sobie w onCreare TimerTask-a () który będzie odrysowywał kolejne bitmapy co ustalony czas. Powinno zadziałać ok :)

pzdr

0

Dziękuję za pomoc.

1 użytkowników online, w tym zalogowanych: 0, gości: 1