Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core / src / org / xwalk / core / XWalkPreferences.java
index d2cf5df..3c0a7c5 100644 (file)
@@ -4,87 +4,65 @@
 
 package org.xwalk.core;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
+import org.xwalk.core.internal.XWalkPreferencesInternal;
 
 /**
- * This class is not thread-safe and must be called on the UI thread.
+ * This class represents the preferences and could be set by callers.
+ * It is not thread-safe and must be called on the UI thread.
  * Afterwards, the preference could be read from all threads and can impact
  * all XWalkView instances.
  */
-public final class XWalkPreferences {
-    private static HashMap<String, Boolean> sPrefMap = new HashMap<String, Boolean>();
-    private static ArrayList<KeyValueChangeListener> sListeners =
-            new ArrayList<KeyValueChangeListener>();
-
+public final class XWalkPreferences extends XWalkPreferencesInternal {
     /**
      * The key string to enable/disable remote debugging.
+     * @since 1.0
      */
     public static final String REMOTE_DEBUGGING = "remote-debugging";
 
-    static {
-        sPrefMap.put(REMOTE_DEBUGGING, Boolean.FALSE);
-    }
+    /**
+     * The key string to enable/disable animatable XWalkView. Default value is
+     * false.
+     *
+     * If this key is set to True, the XWalkView created by Crosswalk can be
+     * transformed and animated. Internally, Crosswalk is alternatively using
+     * TextureView as the backend of XWalkView.
+     *
+     * <a href="http://developer.android.com/reference/android/view/TextureView.html">
+     * TextureView</a> is a kind of
+     * <a href="http://developer.android.com/reference/android/view/View.html">
+     * android.view.View</a> that is different from
+     * <a href="http://developer.android.com/reference/android/view/SurfaceView.html">
+     * SurfaceView</a>. Unlike SurfaceView, it can be resized, transformed and
+     * animated. Once this key is set to True, all XWalkView will use TextureView
+     * as the rendering target instead of SurfaceView. The downside of TextureView
+     * is, it would consume more graphics memory than SurfaceView and may have
+     * 1~3 extra frames of latency to display updates.
+     *
+     * Note this key MUST be set before creating the first XWalkView, otherwise
+     * a RuntimeException will be thrown.
+     * @since 2.0
+     */
+    public static final String ANIMATABLE_XWALK_VIEW = "animatable-xwalk-view";
 
     /**
      * Set a preference value into Crosswalk. An exception will be thrown if
      * the key for the preference is not valid.
      * @param key the string name of the key.
      * @param enabled true if setting it as enabled.
+     * @since 1.0
      */
     public static synchronized void setValue(String key, boolean enabled) throws RuntimeException {
-        checkKey(key);
-        if (sPrefMap.get(key) != enabled) {
-            sPrefMap.put(key, new Boolean(enabled));
-            onKeyValueChanged(key, enabled);
-        }
+        XWalkPreferencesInternal.setValue(key, enabled);
     }
 
     /**
-     * Get a preference value into Crosswalk. An exception will be thrown if
+     * Get a preference value from Crosswalk. An exception will be thrown if
      * the key for the preference is not valid.
      * @param key the string name of the key.
      * @return true if it's enabled.
+     * @since 1.0
      */
     public static synchronized boolean getValue(String key) throws RuntimeException {
-        checkKey(key);
-        return sPrefMap.get(key);
+        return XWalkPreferencesInternal.getValue(key);
     }
-
-    // TODO(yongsheng): I believe this is needed?
-    /*public static synchronized void setValue(String key, int value) throws RuntimeException {
-    }*/
-
-    static synchronized void load(KeyValueChangeListener listener) {
-        // Load current settings for initialization of a listener implementor.
-        for (Map.Entry<String, Boolean> entry : sPrefMap.entrySet()) {
-            listener.onKeyValueChanged(entry.getKey(), entry.getValue());
-        }
-
-        registerListener(listener);
-    }
-
-    // Listen to value changes.
-    interface KeyValueChangeListener {
-        public void onKeyValueChanged(String key, boolean value);
-    }
-
-    private static synchronized void registerListener(KeyValueChangeListener listener) {
-        sListeners.add(listener);
-    }
-
-    private static void onKeyValueChanged(String key, boolean enabled) {
-        for (KeyValueChangeListener listener : sListeners) {
-            listener.onKeyValueChanged(key, enabled);
-        }
-    }
-
-    private static void checkKey(String key) throws RuntimeException {
-        if (!sPrefMap.containsKey(key)) {
-            throw new RuntimeException("Warning: the preference key " + key +
-                    " is not supported by Crosswalk.");
-        }
-    }
-
 }