changed AddBookmark UI
make folder editing and add folder button mutually
exclusive
use ok button in edit folder name mode in addition to
soft keyboard enter
fixed folder list on startup
Change-Id: Ie0bec93f1afe1f16e1693086f2fb25fd5ff723ad
diff --git a/res/layout/browser_add_bookmark.xml b/res/layout/browser_add_bookmark.xml
index e22e820..604bda8 100644
--- a/res/layout/browser_add_bookmark.xml
+++ b/res/layout/browser_add_bookmark.xml
@@ -113,7 +113,7 @@
</RelativeLayout>
<LinearLayout android:id="@+id/folder_selector"
- android:layout_width="wrap_content"
+ android:layout_width="500dip"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone"
@@ -121,26 +121,35 @@
<TextView
android:id="@+id/path"
+ android:layout_marginTop="4dip"
+ android:layout_marginLeft="16dip"
+ android:layout_marginRight="16dip"
+ android:layout_marginBottom="4dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="start"
android:text="@string/bookmarks"
- android:textAppearance="?android:attr/textAppearanceMedium" />
+ android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/list"
- android:layout_width="wrap_content"
+ android:layout_marginLeft="16dip"
+ android:layout_marginRight="16dip"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/folder_namer"
+ android:layout_marginLeft="16dip"
+ android:layout_marginRight="16dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button
android:id="@+id/add_new_folder"
+ android_marginTop="16dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
diff --git a/res/layout/folder_list_item.xml b/res/layout/folder_list_item.xml
new file mode 100644
index 0000000..56c597b
--- /dev/null
+++ b/res/layout/folder_list_item.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 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.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <ImageView
+ android:id="@+id/icon1"
+ style="@style/HoloIcon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:src="@drawable/ic_go_normal_white" />
+ <TextView
+ android:id="@android:id/text1"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="center_vertical"
+ android:paddingLeft="6dip"
+ android:minHeight="?android:attr/listPreferredItemHeight" />
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 33e30b0..6649f3d 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -131,7 +131,7 @@
<!-- Default name for a new folder -->
<string name="new_folder">New folder</string>
<!-- Field label in Bookmark dialog box: title that the user wishes to use for the bookmark -->
- <string name="name">label</string>
+ <string name="name">Label</string>
<!-- Initial value in Location field in Bookmark dialog box -->
<string name="http">http://</string>
<!-- Menu item that opens a dialog to save a bookmark for the current page -->
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 5da4d2a..a3cd688 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -21,6 +21,7 @@
import android.app.Activity;
import android.app.LoaderManager;
import android.content.ContentResolver;
+import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.CursorLoader;
@@ -31,6 +32,7 @@
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.ParseException;
+import android.net.Uri;
import android.net.WebAddress;
import android.os.Bundle;
import android.os.Handler;
@@ -55,9 +57,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
-import java.util.Date;
-
-import android.util.Log;
public class AddBookmarkPage extends Activity
implements View.OnClickListener, TextView.OnEditorActionListener,
@@ -109,17 +108,11 @@
if (actionId == EditorInfo.IME_NULL) {
// Only want to do this once.
if (event.getAction() == KeyEvent.ACTION_UP) {
- // Add the folder to the database
- ContentValues values = new ContentValues();
- values.put(BrowserContract.Bookmarks.TITLE,
- v.getText().toString());
- values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
- values.put(BrowserContract.Bookmarks.PARENT,
- mCurrentFolder);
- getContentResolver().insert(
- BrowserContract.Bookmarks.CONTENT_URI, values);
-
+ String name = v.getText().toString();
+ long id = addFolderToCurrent(name);
mFolderNamer.setVisibility(View.GONE);
+ mAddNewFolder.setVisibility(View.VISIBLE);
+ descendInto(name,id);
InputMethodManager.getInstance(this)
.hideSoftInputFromWindow(
mFolderNamer.getWindowToken(), 0);
@@ -136,33 +129,74 @@
public void onClick(View v) {
if (v == mButton) {
if (mFolderSelector.getVisibility() == View.VISIBLE) {
- // We are showing the folder selector. This means that the user
- // has selected a folder. Go back to the opening page
- mFolderSelector.setVisibility(View.GONE);
- mDefaultView.setVisibility(View.VISIBLE);
- setTitle(R.string.bookmark_this_page);
+ // We are showing the folder selector.
+ if (mFolderNamer.getVisibility() == View.VISIBLE) {
+ // Editing folder name
+ String name = mFolderNamer.getText().toString();
+ long id = addFolderToCurrent(mFolderNamer.getText().toString());
+ descendInto(name, id);
+ mFolderNamer.setVisibility(View.GONE);
+ mAddNewFolder.setVisibility(View.VISIBLE);
+ } else {
+ // User has selected a folder. Go back to the opening page
+ mFolderSelector.setVisibility(View.GONE);
+ mDefaultView.setVisibility(View.VISIBLE);
+ setTitle(R.string.bookmark_this_page);
+ }
} else if (save()) {
finish();
}
} else if (v == mCancelButton) {
- finish();
+ if (mFolderNamer.getVisibility() == View.VISIBLE) {
+ mFolderNamer.setVisibility(View.GONE);
+ mAddNewFolder.setVisibility(View.VISIBLE);
+ } else {
+ finish();
+ }
} else if (v == mFolder) {
switchToFolderSelector();
} else if (v == mAddNewFolder) {
mFolderNamer.setVisibility(View.VISIBLE);
mFolderNamer.setText(R.string.new_folder);
mFolderNamer.requestFocus();
+ mAddNewFolder.setVisibility(View.GONE);
InputMethodManager.getInstance(this).showSoftInput(mFolderNamer,
InputMethodManager.SHOW_IMPLICIT);
}
}
+ private long addFolderToCurrent(String name) {
+ // Add the folder to the database
+ ContentValues values = new ContentValues();
+ values.put(BrowserContract.Bookmarks.TITLE,
+ name);
+ values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
+ values.put(BrowserContract.Bookmarks.PARENT,
+ mCurrentFolder);
+ Uri uri = getContentResolver().insert(
+ BrowserContract.Bookmarks.CONTENT_URI, values);
+ if (uri != null) {
+ return ContentUris.parseId(uri);
+ } else {
+ return -1;
+ }
+ }
+
private void switchToFolderSelector() {
mDefaultView.setVisibility(View.GONE);
mFolderSelector.setVisibility(View.VISIBLE);
setTitle(R.string.containing_folder);
}
+ private void descendInto(String foldername, long id) {
+ if (id != -1) {
+ mCurrentFolder = id;
+ mPaths.add(new Folder(foldername, id));
+ updatePathString();
+ getLoaderManager().restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
+ }
+ }
+
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection;
@@ -186,7 +220,6 @@
BrowserContract.Bookmarks.TITLE,
BrowserContract.Bookmarks.IS_FOLDER
};
-
return new CursorLoader(this,
BrowserContract.Bookmarks.buildFolderUri(
mCurrentFolder),
@@ -213,7 +246,8 @@
BrowserContract.Bookmarks.TITLE);
int parentIndex = cursor.getColumnIndexOrThrow(
BrowserContract.Bookmarks.PARENT);
- while (parent != BrowserProvider2.FIXED_ID_ROOT) {
+ while ((parent != BrowserProvider2.FIXED_ID_ROOT) &&
+ (parent != 0)) {
// First, find the folder corresponding to the current
// folder
if (!cursor.moveToFirst()) {
@@ -257,11 +291,7 @@
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// Switch to the folder that was clicked on.
- mCurrentFolder = id;
- mPaths.add(new Folder(((TextView) view).getText().toString(), id));
- updatePathString();
-
- getLoaderManager().restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
+ descendInto(((TextView) view).getText().toString(), id);
}
/**
@@ -281,8 +311,11 @@
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
- return LayoutInflater.from(context).inflate(
- android.R.layout.simple_list_item_1, null);
+ View view = LayoutInflater.from(context).inflate(
+ R.layout.folder_list_item, null);
+ view.setBackgroundDrawable(context.getResources().
+ getDrawable(android.R.drawable.list_selector_background));
+ return view;
}
}
@@ -296,7 +329,7 @@
setTitle(R.string.bookmark_this_page);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_list_bookmark);
-
+
String title = null;
String url = null;
@@ -345,7 +378,7 @@
ListView list = (ListView) findViewById(R.id.list);
mPaths = new ArrayList<Folder>();
- mPaths.add(0, new Folder(getString(R.string.bookmarks), 0));
+ mPaths.add(0, new Folder(getString(R.string.bookmarks), BrowserProvider2.FIXED_ID_ROOT));
mAdapter = new FolderAdapter(this);
list.setAdapter(mAdapter);
list.setOnItemClickListener(this);
@@ -356,7 +389,7 @@
}
manager.initLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
-
+
if (!getWindow().getDecorView().isInTouchMode()) {
mButton.requestFocus();
}
@@ -397,21 +430,27 @@
}
@Override
- public boolean dispatchKeyEvent (KeyEvent event) {
+ public boolean dispatchKeyEvent(KeyEvent event) {
if (mFolderSelector.getVisibility() == View.VISIBLE
&& KeyEvent.KEYCODE_BACK == event.getKeyCode()) {
if (KeyEvent.ACTION_UP == event.getAction()) {
- int size = mPaths.size();
- if (1 == size) {
- // We have reached the top level
- finish();
+ if (mFolderNamer.getVisibility() == View.VISIBLE) {
+ mFolderNamer.setVisibility(View.GONE);
+ mAddNewFolder.setVisibility(View.VISIBLE);
+ InputMethodManager.getInstance(this).hideSoftInputFromWindow(
+ mFolderNamer.getWindowToken(), 0);
} else {
- // Go up a level
- mPaths.remove(size - 1);
- mCurrentFolder = mPaths.get(size - 2).Id;
- updatePathString();
- getLoaderManager().restartLoader(LOADER_ID_FOLDER_CONTENTS,
- null, this);
+ int size = mPaths.size();
+ if (1 == size) {
+ // We have reached the top level
+ finish();
+ } else {
+ // Go up a level
+ mPaths.remove(size - 1);
+ mCurrentFolder = mPaths.get(size - 2).Id;
+ updatePathString();
+ getLoaderManager().restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
+ }
}
}
return true;