public void setBackwardController(LayerManager.IBackwardContoller backwardControllerForLayer) {
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null) {
       layer.setBackwardController(backwardControllerForLayer);
     }
   }
 }
 private void unbind() {
   assert (!(mCurrentLayer == null ^ mCurrentPlayer == null));
   if (mCurrentLayer == null) return;
   mCurrentPlayer.unRegisterPlayListener(mCurrentLayer);
   mCurrentLayer.onPause();
   mCurrentLayer.setPlayer(null);
   mCurrentLayer.setData(null);
   mCurrentPlayer = null;
   mCurrentLayer = null;
 }
 private void bind(Player player, Layer layer, MediaData data) {
   assert (player != null && layer != null && data != null);
   mCurrentLayer = layer;
   mCurrentPlayer = player;
   mCurrentLayer.setPlayer(player);
   mCurrentLayer.setData(data);
   mCurrentPlayer.registerPlayListener(mCurrentLayer);
   mCurrentLayer.onPrepareOptionsMenu(mOptionsMenu);
   mCurrentLayer.onResume(mIsFilmMode);
 }
 @Override
 public void onLayout(boolean changeSize, int left, int top, int right, int bottom) {
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null && layer.getMGLView() != null) {
       layer.getMGLView().doLayout(changeSize, left, top, right, bottom);
     }
   }
 }
 @Override
 public void destroy() {
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null) {
       layer.onDestroy();
     }
   }
 }
 @Override
 public void init(ViewGroup rootView, MGLView glRootView) {
   mRootView = rootView;
   mGLRootView = glRootView;
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null) {
       layer.onCreate(mActivity, mRootView);
     }
   }
 }
 public boolean onCreateOptionsMenu(Menu menu) {
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   Layer layer;
   while (itr.hasNext()) {
     layer = itr.next().getValue();
     if (layer != null) {
       layer.onCreateOptionsMenu(menu);
     }
   }
   mOptionsMenu = menu;
   return true;
 }
 @Override
 public void resume() {
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null) {
       if (mRootView != null && layer.getView() != null) {
         mRootView.addView(layer.getView());
       }
       if (mGLRootView != null && layer.getMGLView() != null) {
         mGLRootView.addComponent(layer.getMGLView());
       }
       layer.onActivityResume();
     }
   }
 }
 public boolean onActionBarVisibilityChange(boolean newVisibility) {
   boolean shouldBarControlledByLayerManager = false;
   if (mCurrentLayer != null) {
     shouldBarControlledByLayerManager = mCurrentLayer.onActionBarVisibilityChange(newVisibility);
   }
   return shouldBarControlledByLayerManager;
 }
 @Override
 public void onFilmModeChange(boolean isFilmMode) {
   if (isFilmMode == mIsFilmMode) return;
   mIsFilmMode = isFilmMode;
   if (mCurrentLayer != null) {
     mCurrentLayer.onFilmModeChange(mIsFilmMode);
   }
 }
 @Override
 public void pause() {
   Iterator<Entry<MediaType, Layer>> itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null) {
       layer.onActivityPause();
     }
   }
   unbind();
   itr = mLayers.entrySet().iterator();
   while (itr.hasNext()) {
     Layer layer = itr.next().getValue();
     if (layer != null) {
       if (mRootView != null && layer.getView() != null) {
         mRootView.removeView(layer.getView());
       }
       if (mGLRootView != null && layer.getMGLView() != null) {
         mGLRootView.removeComponent(layer.getMGLView());
       }
     }
   }
 }
 @Override
 public void onKeyEvent(KeyEvent event) {
   if (mCurrentLayer != null) {
     mCurrentLayer.onKeyEvent(event);
   }
 }
 public boolean onOptionsItemSelected(MenuItem item) {
   if (mCurrentLayer != null) {
     mCurrentLayer.onOptionsItemSelected(item);
   }
   return true;
 }
 public boolean onPrepareOptionsMenu(Menu menu) {
   if (mCurrentLayer != null) {
     mCurrentLayer.onPrepareOptionsMenu(menu);
   }
   return true;
 }
 @Override
 public void drawLayer(MGLCanvas canvas, int width, int height) {
   if (mCurrentLayer != null && mCurrentLayer.getMGLView() != null)
     mCurrentLayer.getMGLView().doDraw(canvas, width, height);
 }