Use current bookmark folder for adding new bookmarks

The browser will use the current folder as default choise if
the user navigates to a bookmark folder and adds a new bookmark.

CR-Fixed: 780852

Change-Id: Ifbacffde6215ff92ab8f4e9e0f5d59ba86a73503
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 56a2f97..eb242c9 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -167,6 +167,33 @@
         return BrowserContract.Bookmarks.buildFolderUri(folder);
     }
 
+    private String getNameFromId(long mCurrentFolder2) {
+        String title = "";
+        Cursor cursor = null;
+        try {
+            cursor = getApplicationContext().getContentResolver().query(
+                    BrowserContract.Bookmarks.CONTENT_URI,
+                    new String[] {
+                            BrowserContract.Bookmarks.TITLE
+                    },
+                    BrowserContract.Bookmarks._ID + " = ? AND "
+                            + BrowserContract.Bookmarks.IS_DELETED + " = ? AND "
+                            + BrowserContract.Bookmarks.IS_FOLDER + " = ? ", new String[] {
+                            String.valueOf(mCurrentFolder2), 0 + "", 1 + ""
+                    }, null);
+            if (cursor != null && cursor.getCount() != 0) {
+                while (cursor.moveToNext()) {
+                    title = cursor.getString(0);
+                }
+            }
+        } finally {
+            if (cursor != null) {
+                cursor.close();
+            }
+        }
+        return title;
+    }
+
     @Override
     public void onTop(BreadCrumbView view, int level, Object data) {
         if (null == data) return;
@@ -732,6 +759,11 @@
             mButton.requestFocus();
         }
 
+        if (!(mCurrentFolder == -1 || mCurrentFolder == 2)) {
+            mFolder.setSelectionIgnoringSelectionChange(2);
+            mFolderAdapter.setOtherFolderDisplayText(getNameFromId(mCurrentFolder));
+        }
+
         getLoaderManager().restartLoader(LOADER_ID_ACCOUNTS, null, this);
     }
 
@@ -745,7 +777,6 @@
     // Called once we have determined which folder is the root folder
     private void onRootFolderFound(long root) {
         mRootFolder = root;
-        mCurrentFolder = mRootFolder;
         setupTopCrumb();
         onCurrentFolderFound();
     }