Make snapshot go live a popup menu

 Bug: 4982126

Change-Id: Ic4b6b645e8ec29f18e3b9fcdaf5f4a12ce58de4c
diff --git a/res/menu/snapshot_go_live.xml b/res/menu/snapshot_go_live.xml
new file mode 100644
index 0000000..aa6b38e
--- /dev/null
+++ b/res/menu/snapshot_go_live.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:id="@+id/snapshot_go_live"
+        android:title="@string/snapshot_go_live" />
+</menu>
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ee3ce95..6c1b102 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1010,4 +1010,6 @@
     <string name="empty_snapshots_folder">There are no saved pages.</string>
     <!-- Menu option to delete the currently selected saved page [CHAR LIMIT=50] -->
     <string name="remove_snapshot">Delete saved page</string>
+    <!-- Popup menu option to load the live version of a saved page [CHAR LIMIT=20] -->
+    <string name="snapshot_go_live">Go live</string>
 </resources>
diff --git a/src/com/android/browser/SnapshotBar.java b/src/com/android/browser/SnapshotBar.java
index 9fb68cf..ba0bf98 100644
--- a/src/com/android/browser/SnapshotBar.java
+++ b/src/com/android/browser/SnapshotBar.java
@@ -23,16 +23,22 @@
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.view.Menu;
+import android.view.MenuItem;
 import android.view.ViewConfiguration;
 import android.view.ViewPropertyAnimator;
+import android.webkit.WebView;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
+import android.widget.PopupMenu;
+import android.widget.PopupMenu.OnMenuItemClickListener;
 import android.widget.TextView;
 
 import java.text.DateFormat;
 import java.util.Date;
 
-public class SnapshotBar extends LinearLayout implements OnClickListener {
+public class SnapshotBar extends LinearLayout implements OnClickListener,
+        OnMenuItemClickListener {
 
     private static final int MSG_SHOW_TITLE = 1;
     private static final long DURATION_SHOW_DATE = BaseUi.HIDE_TITLEBAR_DELAY;
@@ -171,7 +177,11 @@
         if (mBookmarks == v) {
             mTitleBar.getUiController().bookmarksOrHistoryPicker(false);
         } else if (mGoLive == v) {
-            goLive();
+            PopupMenu popup = new PopupMenu(mContext, mGoLive);
+            Menu menu = popup.getMenu();
+            popup.getMenuInflater().inflate(R.menu.snapshot_go_live, menu);
+            popup.setOnMenuItemClickListener(this);
+            popup.show();
         } else if (mTabSwitcher == v) {
             ((PhoneUi) mTitleBar.getUi()).toggleNavScreen();
         } else if (mOverflowMenu == v) {
@@ -188,6 +198,16 @@
         }
     }
 
+    @Override
+    public boolean onMenuItemClick(MenuItem item) {
+        switch (item.getItemId()) {
+        case R.id.snapshot_go_live:
+            goLive();
+            return true;
+        }
+        return false;
+    }
+
     private void goLive() {
         Tab t = mTitleBar.getUi().getActiveTab();
         t.loadUrl(t.getUrl(), null);