#StackBounty: #java #performance #android #error-handling #generics Custom MediaController with full screen video image option

Bounty: 150

I have overridden setAnchorView() of MediaController class to display full screen option icon using below code.The code seems to be working fine in devices I tested but I have few doubts for which I need review-

  • The class assumes the anchor view is a FrameLayout to position full
    screen imageview.
  • Should I use try catch inside setAnchorView?

public class FullScreenMediaController extends MediaController {

    private final Boolean isFullScreen;
    private final Listener listener;

    public FullScreenMediaController(Context context, Listener listener, Boolean isFullScreen) {
        super(context);
        this.listener = listener;
        this.isFullScreen = isFullScreen;
    }

    @Override
    public void setAnchorView(View view) {

        super.setAnchorView(view);

        //image view for full screen to be added to media controller
        ImageView fullScreen = new ImageView(super.getContext());

        FrameLayout.LayoutParams params =
                new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                        LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.RIGHT;
        params.rightMargin = 50;
        params.topMargin = 20;
        fullScreen.setPadding(10, 10, 10, 10);
        addView(fullScreen, params);


        if (isFullScreen) {
            fullScreen.setImageResource(R.drawable.ic_fullscreen_exit);
        } else {
            fullScreen.setImageResource(R.drawable.ic_fullscreen);
        }

        //add listener to image view to handle full screen and exit full screen events
        fullScreen.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onFullScreenClick();
            }
        });
    }

    public interface Listener {
        void onFullScreenClick();
    }
}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.