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.
5 package org.xwalk.core.sample;
7 import org.xwalk.core.XWalkView;
8 import org.xwalk.core.XWalkPreferences;
10 import android.animation.Animator;
11 import android.animation.AnimatorListenerAdapter;
12 import android.animation.AnimatorSet;
13 import android.animation.ObjectAnimator;
14 import android.app.Activity;
15 import android.os.Bundle;
16 import android.widget.Button;
17 import android.widget.LinearLayout;
18 import android.view.View;
21 * Sample code to show how to use ANIMATED_XWALK_VIEW preference key to create
22 * animated XWalkView and apply alpha animation or scale animation on it.
24 public class AnimatableXWalkViewActivity extends XWalkBaseActivity {
25 private final static float ANIMATION_FACTOR = 0.6f;
26 private Button mRunAnimationButton;
28 private void startAnimation() {
29 AnimatorSet combo = new AnimatorSet();
31 float targetAlpha = mXWalkView.getAlpha() == 1.f ? ANIMATION_FACTOR : 1.f;
32 float targetScaleFactor = mXWalkView.getScaleX() == 1.f ? ANIMATION_FACTOR : 1.f;
34 ObjectAnimator fade = ObjectAnimator.ofFloat(mXWalkView,
35 "alpha", mXWalkView.getAlpha(), targetAlpha);
36 ObjectAnimator scaleX = ObjectAnimator.ofFloat(mXWalkView,
37 "scaleX", mXWalkView.getScaleX(), targetScaleFactor);
38 ObjectAnimator scaleY = ObjectAnimator.ofFloat(mXWalkView,
39 "scaleY", mXWalkView.getScaleY(), targetScaleFactor);
41 combo.setDuration(400);
42 combo.playTogether(fade, scaleX, scaleY);
47 protected void onCreate(Bundle savedInstanceState) {
48 super.onCreate(savedInstanceState);
50 // ANIMATABLE_XWALK_VIEW preference key MUST be set before XWalkView creation.
51 XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true);
53 setContentView(R.layout.animatable_xwview_layout);
55 mRunAnimationButton = (Button) findViewById(R.id.run_animation);
56 mRunAnimationButton.setOnClickListener(new View.OnClickListener() {
58 public void onClick(View v) {
63 mXWalkView = (XWalkView) findViewById(R.id.xwalkview);
64 mXWalkView.load("http://www.baidu.com", null);
68 public void onDestroy() {
71 // Reset the preference for animatable XWalkView.
72 XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, false);