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 java.lang.ref.WeakReference;
9 import android.app.Activity;
10 import android.content.Context;
11 import android.os.Bundle;
12 import android.view.View;
14 import org.xwalk.core.internal.XWalkClient;
15 import org.xwalk.core.internal.XWalkUIClientInternal;
16 import org.xwalk.core.internal.XWalkViewInternal;
19 * Represents the content to be presented on the secondary display.
21 public class XWalkPresentationContent {
22 public final int INVALID_PRESENTATION_ID = -1;
24 private int mPresentationId = INVALID_PRESENTATION_ID;
25 private XWalkViewInternal mContentView;
26 private Context mContext;
27 private WeakReference<Activity> mActivity;
28 private PresentationDelegate mDelegate;
31 public XWalkPresentationContent(
32 Context context, WeakReference<Activity> activity, PresentationDelegate delegate) {
38 public void load(final String url) {
39 Activity activity = mActivity.get();
40 if (activity == null) return;
42 if (mContentView == null) {
43 mContentView = new XWalkViewInternal(mContext, activity);
44 final XWalkUIClientInternal xWalkUIClient = new XWalkUIClientInternal(mContentView) {
46 public void onJavascriptCloseWindow(XWalkViewInternal view) {
47 // The content was closed already. Web need to invalidate the
48 // presentation id now.
49 mPresentationId = INVALID_PRESENTATION_ID;
54 public void onPageLoadStopped(
55 XWalkViewInternal view, String url, LoadStatusInternal status) {
56 if (status == LoadStatusInternal.FINISHED) {
57 mPresentationId = mContentView.getContentID();
62 mContentView.setUIClient(xWalkUIClient);
64 mContentView.load(url, null);
67 public int getPresentationId() {
68 return mPresentationId;
71 public View getContentView() {
76 mContentView.onDestroy();
77 mPresentationId = INVALID_PRESENTATION_ID;
81 public void onPause() {
82 mContentView.pauseTimers();
83 mContentView.onHide();
86 public void onResume() {
87 mContentView.resumeTimers();
88 mContentView.onShow();
91 private void onContentLoaded() {
92 if (mDelegate != null) mDelegate.onContentLoaded(this);
95 private void onContentClosed() {
96 if (mDelegate != null) mDelegate.onContentClosed(this);
100 * Interface to hook into XWalkPresentationContent instance.
102 public interface PresentationDelegate {
104 * Called when the presentation content is loaded.
106 public void onContentLoaded(XWalkPresentationContent content);
109 * Called when the presentation content is closed.
111 public void onContentClosed(XWalkPresentationContent content);