Temporal edge navigation feature
- User can swipe from left and right edge to go
back and forward in history of a tab
Change-Id: I941f91122510b004bdcb6a718eb6c05730694960
diff --git a/src/com/android/browser/EdgeSwipeModel.java b/src/com/android/browser/EdgeSwipeModel.java
new file mode 100644
index 0000000..51a5dc9
--- /dev/null
+++ b/src/com/android/browser/EdgeSwipeModel.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ * * Neither the name of The Linux Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+package com.android.browser;
+
+import android.graphics.Bitmap;
+import android.util.SparseArray;
+import android.webkit.ValueCallback;
+
+public class EdgeSwipeModel {
+ private SparseArray<Bitmap> mBitmaps;
+ private Tab mTab;
+ private TitleBar mBar;
+
+ private static final int mMinProgress = 85;
+
+ private static final int mMaxBitmaps = 5;
+
+ public EdgeSwipeModel(Tab tab, TitleBar bar) {
+ mTab = tab;
+ mBar = bar;
+ mBitmaps = new SparseArray<>();
+ }
+
+ public void updateSnapshot(final int index) {
+ if (mBitmaps.get(index) != null) {
+ return;
+ }
+
+ int captureIndex = mTab.getCaptureIndex(index);
+
+ boolean bitmapExists = mTab.getWebView().hasSnapshot(captureIndex);
+
+ if (!mTab.isFirstVisualPixelPainted()) {
+ fetchSnapshot(index);
+ return;
+ }
+
+ int progress = mBar.getProgressView().getProgressPercent();
+
+ if (bitmapExists && progress < mMinProgress) {
+ fetchSnapshot(index);
+ return;
+ }
+
+ mTab.getWebView().captureSnapshot(captureIndex,
+ new ValueCallback<Bitmap>() {
+ @Override
+ public void onReceiveValue(Bitmap value) {
+ mBitmaps.put(index, value);
+ }
+ }
+ );
+ }
+
+ public void fetchSnapshot(final int index) {
+ if (mBitmaps.get(index) != null) {
+ return;
+ }
+
+ int captureIndex = mTab.getCaptureIndex(index);
+
+ mTab.getWebView().getSnapshot(captureIndex,
+ new ValueCallback<Bitmap>() {
+ @Override
+ public void onReceiveValue(Bitmap bitmap) {
+ mBitmaps.put(index, bitmap);
+ }
+ }
+ );
+ }
+
+ public Bitmap readSnapshot(int index) {
+ if (index < 0) {
+ return null;
+ }
+
+ if (index > (mTab.getWebView().copyBackForwardList().getSize() - 1)) {
+ return null;
+ }
+
+ return mBitmaps.get(index);
+ }
+
+ public void deleteSnapshot(int index) {
+ mBitmaps.delete(index);
+ }
+
+ public void cleanup() {
+ mBitmaps.clear();
+ }
+}