在Android上从ANE(Adobe Native Extension)运行新的UI后台活动

时间:2017-09-19 16:21:38

标签: android air adobe air-native-extension ane

我尝试根据YouTube API制作Android ANE。

YouTube API需要启动新活动,当通过ANE调用时,禁用Air应用活动,直到用户点击后退按钮。

我有什么选择在后台运行YouTube活动,以便Air应用程序保持互动?

活动类:

/**


* A sample showing how to use the ActionBar as an overlay when the video is playing in fullscreen.
 *
 * The ActionBar is the only view allowed to overlay the player, so it is a useful place to put
 * custom application controls when the video is in fullscreen. The ActionBar can not change back
 * and forth between normal mode and overlay mode, so to make sure our application's content
 * is not covered by the ActionBar we want to pad our root view when we are not in fullscreen.
 */
@TargetApi(11)
public class ActionBarDemoActivity extends YouTubeFailureRecoveryActivity implements
        YouTubePlayer.OnFullscreenListener {

  static public String vidToShow = null;

  private ActionBarPaddedFrameLayout viewContainer;
  private YouTubePlayerFragment playerFragment;
  static public ActionBarDemoActivity inst;
  private YouTubePlayer _player;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    inst = this;
    setContentView(R.layout.action_bar_demo);

    viewContainer = (ActionBarPaddedFrameLayout) findViewById(R.id.view_container);
    playerFragment =
            (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
    playerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);

    //viewContainer.setActionBar(getActionBar());
    // Action bar background is transparent by default.
    //getActionBar().setBackgroundDrawable(new ColorDrawable(0xAA000000));
    //ViewGroup.LayoutParams viewParams = rootView.getLayoutParams();
   /* viewParams.width = 640;
    viewParams.height = 360;*/
  }

  @Override
  public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                                      boolean wasRestored) {
    player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
    player.setOnFullscreenListener(this);
    _player = player;

    if (!wasRestored) {
      player.cueVideo(vidToShow);
    }
  }

  @Override
  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
  }

  @Override
  public void onFullscreen(boolean fullscreen) {
    viewContainer.setEnablePadding(!fullscreen);

    ViewGroup.LayoutParams playerParams = playerFragment.getView().getLayoutParams();
    if (fullscreen) {
      playerParams.width = MATCH_PARENT;
      playerParams.height = MATCH_PARENT;
    } else {
      playerParams.width = WRAP_CONTENT;
      playerParams.height = WRAP_CONTENT;
    }
  }
  /**
   *
   * external methods
   *
   */

  static public void cueVideo(String id){
    inst._player.cueVideo(id);
  }



 /**
   * This is a FrameLayout which adds top-padding equal to the height of the ActionBar unless
   * disabled by {@link #setEnablePadding(boolean)}.
   */
  public static final class ActionBarPaddedFrameLayout extends FrameLayout {
private ActionBar actionBar;
private boolean paddingEnabled;

public ActionBarPaddedFrameLayout(Context context) {
  this(context, null);
}

public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs) {
  this(context, attrs, 0);
}

public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  paddingEnabled = true;
}

public void setActionBar(ActionBar actionBar) {
  this.actionBar = actionBar;
  requestLayout();
}

public void setEnablePadding(boolean enable) {
  paddingEnabled = enable;
  requestLayout();
}

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     /* int topPadding =
              paddingEnabled && actionBar != null && actionBar.isShowing() ? actionBar.getHeight() : 0;
      setPadding(0, topPadding, 0, 0);*/

      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }

}

0 个答案:

没有答案