1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.xwalk.core.extension.api.presentation;
7 import android.app.Activity;
8 import android.content.Context;
9 import android.os.Bundle;
10 import android.view.View;
12 import org.xwalk.core.XWalkView;
13 import org.xwalk.core.XWalkClient;
16 * Represents the content to be presented on the secondary display.
18 public class XWalkPresentationContent {
19 public final int INVALID_PRESENTATION_ID = -1;
21 private int mPresentationId = INVALID_PRESENTATION_ID;
22 private XWalkView mContentView;
23 private Context mContext;
24 private Activity mActivity;
25 private PresentationDelegate mDelegate;
27 private final XWalkClient mXWalkClient = new XWalkClient() {
29 public void onPageFinished(XWalkView view, String url) {
30 mPresentationId = mContentView.getContentID();
35 public void onCloseWindow(XWalkView view) {
36 // The content was closed already. Web need to invalidate the
37 // presentation id now.
38 mPresentationId = INVALID_PRESENTATION_ID;
43 public XWalkPresentationContent(Context context, Activity activity, PresentationDelegate delegate) {
49 public void load(final String url) {
50 if (mContentView == null) {
51 mContentView = new XWalkView(mContext, mActivity);
52 mContentView.setXWalkClient(mXWalkClient);
54 mContentView.loadUrl(url);
57 public int getPresentationId() {
58 return mPresentationId;
61 public View getContentView() {
66 mContentView.destroy();
67 mPresentationId = INVALID_PRESENTATION_ID;
71 public void onPause() {
72 mContentView.onPause();
75 public void onResume() {
76 mContentView.onResume();
79 private void onContentLoaded() {
80 if (mDelegate != null) mDelegate.onContentLoaded(this);
83 private void onContentClosed() {
84 if (mDelegate != null) mDelegate.onContentClosed(this);
88 * Interface to hook into XWalkPresentationContent instance.
90 public interface PresentationDelegate {
92 * Called when the presentation content is loaded.
94 public void onContentLoaded(XWalkPresentationContent content);
97 * Called when the presentation content is closed.
99 public void onContentClosed(XWalkPresentationContent content);