Upstream version 6.35.131.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / sample / src / org / xwalk / core / sample / XWalkNavigationActivity.java
1 // Copyright (c) 2014 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.
4
5 package org.xwalk.core.sample;
6
7 import org.xwalk.core.XWalkView;
8 import org.xwalk.core.XWalkNavigationHistory;
9
10 import android.app.Activity;
11 import android.os.Bundle;
12 import android.view.View;
13 import android.view.View.OnClickListener;
14 import android.widget.ImageButton;
15
16 public class XWalkNavigationActivity extends Activity {
17
18     private ImageButton mNextButton;
19     private ImageButton mPrevButton;
20     private XWalkView mXWalkView;
21
22     @Override
23     protected void onCreate(Bundle savedInstanceState) {
24         super.onCreate(savedInstanceState);
25         setContentView(R.layout.navigation_layout);
26         mPrevButton = (ImageButton) findViewById(R.id.prev);
27         mNextButton = (ImageButton) findViewById(R.id.next);
28         mXWalkView = (XWalkView) findViewById(R.id.xwalkview);
29
30         mPrevButton.setOnClickListener(new OnClickListener() {
31             @Override
32             public void onClick(View v) {
33                 // Go backward
34                 if (mXWalkView != null &&
35                         mXWalkView.getNavigationHistory().canGoBack()) {
36                     mXWalkView.getNavigationHistory().navigate(
37                             XWalkNavigationHistory.Direction.BACKWARD, 1);
38                 }
39             }
40         });
41
42         mNextButton.setOnClickListener(new OnClickListener() {
43             @Override
44             public void onClick(View v) {
45                 // Go forward
46                 if (mXWalkView != null &&
47                         mXWalkView.getNavigationHistory().canGoForward()) {
48                     mXWalkView.getNavigationHistory().navigate(
49                             XWalkNavigationHistory.Direction.FORWARD, 1);
50                 }
51             }
52         });
53
54         mXWalkView.load("http://www.baidu.com/", null);
55     }
56 }