Example usage for android.widget FrameLayout setOnKeyListener

List of usage examples for android.widget FrameLayout setOnKeyListener

Introduction

In this page you can find the example usage for android.widget FrameLayout setOnKeyListener.

Prototype

public void setOnKeyListener(OnKeyListener l) 

Source Link

Document

Register a callback to be invoked when a hardware key is pressed in this view.

Usage

From source file:org.fossasia.phimpme.leafpic.activities.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(R.id.root);
    findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
        @Override//  w  w w  . j av a 2 s. co  m
        public void onClick(View view) {
            toggleControlsVisibility();
        }
    });

    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));

    shutterView = findViewById(R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    mediaController = new CustomMediaController(this, this);

    mediController_anchor = findViewById(R.id.media_player_anchor);
    mediaController.setAnchorView(root);
    //mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    initUI();

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager)
        CookieHandler.setDefault(defaultCookieManager);

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:org.horaapps.leafpic.activities.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(org.horaapps.leafpic.R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root);
    findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() {
        @Override//from  w  w  w  .  j  av  a  2s  .  c o  m
        public void onClick(View view) {
            toggleControlsVisibility();
        }
    });

    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000));

    shutterView = findViewById(org.horaapps.leafpic.R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    mediaController = new CustomMediaController(this, this);

    mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor);
    mediaController.setAnchorView(root);
    //mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar);
    initUI();

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager)
        CookieHandler.setDefault(defaultCookieManager);

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}

From source file:com.horaapps.leafpic.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override//from   w  ww  . ja  v a2 s.c  o m
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                //view.performClick();
            }
            return true;
        }
    });

    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(R.color.md_black_1000);

    shutterView = findViewById(R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    mediaController = new KeyCompatibleMediaController(this);

    mediController_anchor = findViewById(R.id.media_player_anchor);
    mediaController.setAnchorView(mediController_anchor);
    mediaController.setPaddingRelative(0, 0, 0, Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    initUI();

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager)
        CookieHandler.setDefault(defaultCookieManager);

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}