summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml2
-rw-r--r--res/layout/browser_add_bookmark.xml10
-rw-r--r--res/layout/new_folder_layout.xml38
-rw-r--r--src/com/android/browser/AddBookmarkPage.java89
4 files changed, 106 insertions, 33 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d26aae7..5b844e0 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -177,7 +177,7 @@
<activity android:name="AddBookmarkPage" android:label="Save bookmark"
android:theme="@style/Dialog"
android:configChanges="orientation|keyboardHidden"
- android:windowSoftInputMode="stateHidden">
+ android:windowSoftInputMode="stateHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<category android:name="android.intent.category.DEFAULT" />
diff --git a/res/layout/browser_add_bookmark.xml b/res/layout/browser_add_bookmark.xml
index 8b6feab..a8a87be 100644
--- a/res/layout/browser_add_bookmark.xml
+++ b/res/layout/browser_add_bookmark.xml
@@ -148,7 +148,7 @@
android:visibility="gone"
>
- <ListView
+ <view class="com.android.browser.AddBookmarkPage$CustomListView"
android:id="@+id/list"
android:layout_marginLeft="16dip"
android:layout_marginRight="16dip"
@@ -165,14 +165,6 @@
android:text="@string/no_subfolders"
android:textStyle="italic"
android:textAppearance="?android:attr/textAppearanceMedium" />
- <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"
- />
</LinearLayout>
<LinearLayout
diff --git a/res/layout/new_folder_layout.xml b/res/layout/new_folder_layout.xml
new file mode 100644
index 0000000..a503adc
--- /dev/null
+++ b/res/layout/new_folder_layout.xml
@@ -0,0 +1,38 @@
+<?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.
+-->
+<!-- Keep in sync with folder_list_item.xml -->
+<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" />
+ <EditText
+ android:id="@+id/folder_namer"
+ 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/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java
index 262884b..e03c0f6 100644
--- a/src/com/android/browser/AddBookmarkPage.java
+++ b/src/com/android/browser/AddBookmarkPage.java
@@ -41,6 +41,7 @@ import android.os.Message;
import android.preference.PreferenceManager;
import android.provider.BrowserContract;
import android.text.TextUtils;
+import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -97,6 +98,8 @@ public class AddBookmarkPage extends Activity
private View mDefaultView;
private View mFolderSelector;
private EditText mFolderNamer;
+ private boolean mIsFolderNamerShowing;
+ private View mFolderNamerHolder;
private View mAddNewFolder;
private View mAddSeparator;
private long mCurrentFolder = 0;
@@ -104,7 +107,7 @@ public class AddBookmarkPage extends Activity
private BreadCrumbView mCrumbs;
private TextView mFakeTitle;
private View mCrumbHolder;
- private ListView mListView;
+ private CustomListView mListView;
private boolean mSaveToHomeScreen;
private long mRootFolder;
@@ -151,7 +154,7 @@ public class AddBookmarkPage extends Activity
LOADER_ID_FOLDER_CONTENTS));
loader.setUri(getUriForFolder(folder));
loader.forceLoad();
- if (mFolderNamer.getVisibility() == View.VISIBLE) {
+ if (mIsFolderNamerShowing) {
completeOrCancelFolderNaming(true);
}
}
@@ -197,7 +200,7 @@ public class AddBookmarkPage extends Activity
if (v == mButton) {
if (mFolderSelector.getVisibility() == View.VISIBLE) {
// We are showing the folder selector.
- if (mFolderNamer.getVisibility() == View.VISIBLE) {
+ if (mIsFolderNamerShowing) {
completeOrCancelFolderNaming(false);
} else {
// User has selected a folder. Go back to the opening page
@@ -208,7 +211,7 @@ public class AddBookmarkPage extends Activity
finish();
}
} else if (v == mCancelButton) {
- if (mFolderNamer.getVisibility() == View.VISIBLE) {
+ if (mIsFolderNamerShowing) {
completeOrCancelFolderNaming(true);
} else if (mFolderSelector.getVisibility() == View.VISIBLE) {
switchToDefaultView(false);
@@ -225,14 +228,16 @@ public class AddBookmarkPage extends Activity
popup.setOnMenuItemClickListener(this);
popup.show();
} else if (v == mAddNewFolder) {
- mFolderNamer.setVisibility(View.VISIBLE);
+ setShowFolderNamer(true);
mFolderNamer.setText(R.string.new_folder);
mFolderNamer.requestFocus();
- updateList();
mAddNewFolder.setVisibility(View.GONE);
mAddSeparator.setVisibility(View.GONE);
- getInputMethodManager().showSoftInput(mFolderNamer,
- InputMethodManager.SHOW_IMPLICIT);
+ InputMethodManager imm = getInputMethodManager();
+ // Set the InputMethodManager to focus on the ListView so that it
+ // can transfer the focus to mFolderNamer.
+ imm.focusIn(mListView);
+ imm.showSoftInput(mFolderNamer, InputMethodManager.SHOW_IMPLICIT);
}
}
@@ -258,27 +263,17 @@ public class AddBookmarkPage extends Activity
return true;
}
- // Refresh the ListView to hide or show the empty view, as necessary.
- // Should be called after mFolderNamer is shown or hidden.
- private void updateList() {
- if (mAdapter.getCount() == 0) {
- // XXX: Is there a better way to refresh the ListView?
- mListView.setAdapter(mAdapter);
- }
- }
-
private void completeOrCancelFolderNaming(boolean cancel) {
if (!cancel && !TextUtils.isEmpty(mFolderNamer.getText())) {
String name = mFolderNamer.getText().toString();
long id = addFolderToCurrent(mFolderNamer.getText().toString());
descendInto(name, id);
}
- mFolderNamer.setVisibility(View.GONE);
+ setShowFolderNamer(false);
mAddNewFolder.setVisibility(View.VISIBLE);
mAddSeparator.setVisibility(View.VISIBLE);
getInputMethodManager().hideSoftInputFromWindow(
- mFolderNamer.getWindowToken(), 0);
- updateList();
+ mListView.getWindowToken(), 0);
}
private long addFolderToCurrent(String name) {
@@ -461,6 +456,24 @@ public class AddBookmarkPage extends Activity
descendInto(tv.getText().toString(), id);
}
+ private void setShowFolderNamer(boolean show) {
+ if (show != mIsFolderNamerShowing) {
+ mIsFolderNamerShowing = show;
+ if (show) {
+ // Set the selection to the folder namer so it will be in
+ // view.
+ mListView.addFooterView(mFolderNamerHolder);
+ } else {
+ mListView.removeFooterView(mFolderNamerHolder);
+ }
+ // Refresh the list.
+ mListView.setAdapter(mAdapter);
+ if (show) {
+ mListView.setSelection(mListView.getCount() - 1);
+ }
+ }
+ }
+
/**
* Shows a list of names of folders.
*/
@@ -488,7 +501,7 @@ public class AddBookmarkPage extends Activity
@Override
public boolean isEmpty() {
// Do not show the empty view if the user is creating a new folder.
- return super.isEmpty() && mFolderNamer.getVisibility() == View.GONE;
+ return super.isEmpty() && !mIsFolderNamerShowing;
}
}
@@ -554,7 +567,8 @@ public class AddBookmarkPage extends Activity
mDefaultView = findViewById(R.id.default_view);
mFolderSelector = findViewById(R.id.folder_selector);
- mFolderNamer = (EditText) findViewById(R.id.folder_namer);
+ mFolderNamerHolder = getLayoutInflater().inflate(R.layout.new_folder_layout, null);
+ mFolderNamer = (EditText) mFolderNamerHolder.findViewById(R.id.folder_namer);
mFolderNamer.setOnEditorActionListener(this);
mAddNewFolder = findViewById(R.id.add_new_folder);
@@ -570,11 +584,12 @@ public class AddBookmarkPage extends Activity
mCrumbs.setMaxVisible(MAX_CRUMBS_SHOWN);
mAdapter = new FolderAdapter(this);
- mListView = (ListView) findViewById(R.id.list);
+ mListView = (CustomListView) findViewById(R.id.list);
View empty = findViewById(R.id.empty);
mListView.setEmptyView(empty);
mListView.setAdapter(mAdapter);
mListView.setOnItemClickListener(this);
+ mListView.addEditText(mFolderNamer);
LoaderManager manager = getLoaderManager();
if (mCurrentFolder != mRootFolder) {
// Find all the folders
@@ -848,4 +863,32 @@ public class AddBookmarkPage extends Activity
}
return true;
}
+
+ /*
+ * Class used as a proxy for the InputMethodManager to get to mFolderNamer
+ */
+ public static class CustomListView extends ListView {
+ private EditText mEditText;
+
+ public void addEditText(EditText editText) {
+ mEditText = editText;
+ }
+
+ public CustomListView(Context context) {
+ super(context);
+ }
+
+ public CustomListView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public CustomListView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public boolean checkInputConnectionProxy(View view) {
+ return view == mEditText;
+ }
+ }
}