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.internal.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.internal.XWalkClient;
13 import org.xwalk.core.internal.XWalkUIClientInternal;
14 import org.xwalk.core.internal.XWalkViewInternal;
17 * Represents the content to be presented on the secondary display.
19 public class XWalkPresentationContent {
20 public final int INVALID_PRESENTATION_ID = -1;
22 private int mPresentationId = INVALID_PRESENTATION_ID;
23 private XWalkViewInternal mContentView;
24 private Context mContext;
25 private Activity mActivity;
26 private PresentationDelegate mDelegate;
29 public XWalkPresentationContent(Context context, Activity activity, PresentationDelegate delegate) {
35 public void load(final String url) {
36 if (mContentView == null) {
37 mContentView = new XWalkViewInternal(mContext, mActivity);
38 final XWalkClient xWalkClient = new XWalkClient(mContentView) {
40 public void onPageFinished(XWalkViewInternal view, String url) {
41 mPresentationId = mContentView.getContentID();
45 mContentView.setXWalkClient(xWalkClient);
47 final XWalkUIClientInternal xWalkUIClient = new XWalkUIClientInternal(mContentView) {
49 public void onJavascriptCloseWindow(XWalkViewInternal view) {
50 // The content was closed already. Web need to invalidate the
51 // presentation id now.
52 mPresentationId = INVALID_PRESENTATION_ID;
56 mContentView.setUIClient(xWalkUIClient);
58 mContentView.load(url, null);
61 public int getPresentationId() {
62 return mPresentationId;
65 public View getContentView() {
70 mContentView.onDestroy();
71 mPresentationId = INVALID_PRESENTATION_ID;
75 public void onPause() {
76 mContentView.pauseTimers();
77 mContentView.onHide();
80 public void onResume() {
81 mContentView.resumeTimers();
82 mContentView.onShow();
85 private void onContentLoaded() {
86 if (mDelegate != null) mDelegate.onContentLoaded(this);
89 private void onContentClosed() {
90 if (mDelegate != null) mDelegate.onContentClosed(this);
94 * Interface to hook into XWalkPresentationContent instance.
96 public interface PresentationDelegate {
98 * Called when the presentation content is loaded.
100 public void onContentLoaded(XWalkPresentationContent content);
103 * Called when the presentation content is closed.
105 public void onContentClosed(XWalkPresentationContent content);