Get the current ViewFlipper while flipping it

Is there any way to know what the view view is displayed on ViewFlipperwhile it is upside down? I have this problem: mine ViewFlippercontains some images and one video. I want when the viewflipper displays Videoviewwith the video ViewFlipper, to stop flipping and the video to start playback. This only works when the video is displayed for the first time. After that, the video is displayed as an image, and I do not know how to catch the moment the video was displayed. Can someone help me please?

This is how I populate the ViewFlipper:

private void populate() {
        for (int i = 0; i < jArray.length(); i++) {
            System.out.println("lungime " + jArray.length());
            LinearLayout l = new LinearLayout(this);
            l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
            l.setBackgroundColor(0x000000);
            l.setOrientation(LinearLayout.VERTICAL);
            vf.addView(l);

            File f = new File(Environment.getExternalStorageDirectory()
                    + "/Images" + "/");

            File[] files = f.listFiles();

            if (files[i].getName().equals("Video" + idPhotos[i])) {
                System.out.println("Video to Viewflipper");
                System.out.println("Video Path " + files[i].getPath());
                myVideoView = new VideoView(this);
                myVideoView.setVideoPath(files[i].getPath());
                myVideoView.requestFocus();
                myVideoView.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
                l.setBackgroundColor(Color.BLACK);
                myVideoView.setKeepScreenOn(true);

                myVideoView.setOnPreparedListener(new OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        vf.stopFlipping();
                    }

                });
                myVideoView.setOnTouchListener(new OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN: {
                            downXValue = event.getX();
                            break;
                        }

                        case MotionEvent.ACTION_UP: {
                            currentX = event.getX();
                            if (downXValue == currentX) {
                                Intent intent = new Intent(getBaseContext(),
                                        FinActivity.class);
                                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(intent);
                                finish();
                            }
                        }
                        }
                        return true;
                    }

                });

                myVideoView
                        .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            public void onCompletion(MediaPlayer mp) {
                                vf.startFlipping();
                            }
                        });

                vf.stopFlipping();
                myVideoView.start();
                myVideoView.setId(i);
                l.addView(myVideoView);
                l.setId(i);
            }

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 3;
            options.inPurgeable = true;

            bitmap = BitmapFactory.decodeFile(files[i].getPath());
            img = new ImageView(this);
            img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));

            img.setImageBitmap(bitmap);
            img.setOnTouchListener(this);
            l.addView(img);
            l.setId(i);
            img = null;
        }
    }

and on onCreate () method I have this:

if (ff.exists() && (files.length == jArray.length())) {     
                populate();
                vf.setOutAnimation(AnimationUtils.loadAnimation(
                        getBaseContext(), R.anim.push_left_out));
                vf.setInAnimation(AnimationUtils.loadAnimation(
                        getBaseContext(), R.anim.push_left_in));
                vf.startFlipping();
}

(I call the populate () method only once, maybe this is the problem)

Any idea is welcome. Thanks in advance.

+5
2

, , .

, "". AnimationEnd

vf.getDisplayedChild();

. , .

+7

All Articles