diff options
-rw-r--r-- | res/drawable/suggest_item_selector.xml | 22 | ||||
-rw-r--r-- | res/layout/suggestion_item.xml | 67 | ||||
-rw-r--r-- | res/layout/suggestion_two_column.xml | 47 | ||||
-rw-r--r-- | res/values-xlarge/styles.xml | 2 | ||||
-rw-r--r-- | res/values/integers.xml | 2 | ||||
-rw-r--r-- | src/com/android/browser/SuggestionsAdapter.java | 128 | ||||
-rw-r--r-- | src/com/android/browser/UrlInputView.java | 16 |
7 files changed, 92 insertions, 192 deletions
diff --git a/res/drawable/suggest_item_selector.xml b/res/drawable/suggest_item_selector.xml new file mode 100644 index 0000000..777a8fb --- /dev/null +++ b/res/drawable/suggest_item_selector.xml @@ -0,0 +1,22 @@ +<?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. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android" + android:exitFadeDuration="@android:integer/config_mediumAnimTime"> + <item android:state_pressed="true" + android:drawable="@drawable/header_row_press_bookmark_widget_holo" /> + <item android:state_pressed="false" android:drawable="@drawable/clear" /> +</selector> diff --git a/res/layout/suggestion_item.xml b/res/layout/suggestion_item.xml index fd1d851..ab87dd4 100644 --- a/res/layout/suggestion_item.xml +++ b/res/layout/suggestion_item.xml @@ -21,38 +21,45 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="56dip" + android:layout_height="48dip" android:orientation="horizontal" android:gravity="center_vertical" android:baselineAligned="false" > - <ImageView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/icon1" - android:scaleType="center" - style="@style/HoloButton" /> - <RelativeLayout - android:paddingTop="0dip" - android:paddingBottom="0dip" + <LinearLayout + android:id="@+id/suggestion" android:layout_width="0dip" + android:layout_height="match_parent" android:layout_weight="1" - android:layout_height="wrap_content" > - <TextView - android:id="@android:id/text1" - style="@style/SuggestionLineMedium" - android:singleLine="true" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> - <TextView - android:id="@android:id/text2" - style="@style/SuggestionLineSmall" - android:singleLine="true" - android:layout_width="match_parent" + android:orientation="horizontal" + android:background="@drawable/suggest_item_selector"> + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/icon1" + android:layout_gravity="center_vertical" + style="@style/HoloIcon" + android:layout_marginRight="16dip" /> + <LinearLayout + android:layout_width="0dip" android:layout_height="wrap_content" - android:layout_below="@android:id/text1" - android:layout_alignLeft="@android:id/text1" /> - </RelativeLayout> + android:layout_weight="1" + android:layout_gravity="center_vertical" + android:orientation="vertical"> + <TextView + android:id="@android:id/text1" + style="@style/SuggestionLineMedium" + android:singleLine="true" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + <TextView + android:id="@android:id/text2" + style="@style/SuggestionLineSmall" + android:singleLine="true" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + </LinearLayout> + </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" @@ -60,18 +67,14 @@ android:scaleType="center" android:src="@drawable/divider_vert" /> - <ImageButton + <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/icon2" android:scaleType="center" - style="@style/HoloButton" android:src="@drawable/ic_add_string" android:background="@drawable/browserbarbutton" + style="@style/HoloButton" + android:layout_marginRight="16dip" /> - <View - android:id="@+id/spacer" - android:layout_width="16dip" - android:layout_height="match_parent" - /> </LinearLayout> diff --git a/res/layout/suggestion_two_column.xml b/res/layout/suggestion_two_column.xml deleted file mode 100644 index cc4f2e2..0000000 --- a/res/layout/suggestion_two_column.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/* //device/apps/common/assets/res/any/layout/simple_spinner_item.xml -** -** Copyright 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" - android:gravity="center_vertical" - android:baselineAligned="false"> - <include - android:id="@+id/suggest1" - android:layout_height="56dip" - android:layout_width="0dip" - android:layout_weight="1" - layout="@layout/suggestion_item" - /> - <ImageView - android:id="@+id/suggestion_divider" - android:layout_width="wrap_content" - android:layout_height="56dip" - android:background="@drawable/list_divider_vert" /> - <include - android:id="@+id/suggest2" - android:layout_height="56dip" - android:layout_width="0dip" - android:layout_weight="1" - layout="@layout/suggestion_item" - /> -</LinearLayout> diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml index d87a347..f20fd30 100644 --- a/res/values-xlarge/styles.xml +++ b/res/values-xlarge/styles.xml @@ -54,8 +54,10 @@ </style> <style name="SuggestionLineMedium" parent="@android:style/TextAppearance.Holo.Medium.Inverse"> + <item name="android:textSize">16sp</item> </style> <style name="SuggestionLineSmall" parent="@android:style/TextAppearance.Holo.Small.Inverse"> + <item name="android:textSize">12sp</item> </style> </resources> diff --git a/res/values/integers.xml b/res/values/integers.xml index e18676d..a0b7ae3 100644 --- a/res/values/integers.xml +++ b/res/values/integers.xml @@ -13,7 +13,7 @@ <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <!-- The number of lines in the suggestions dropdown in landscape --> - <integer name="max_suggest_lines_landscape">4</integer> + <integer name="max_suggest_lines_landscape">5</integer> <!-- The number of lines in the suggestions dropdown in portrait --> <integer name="max_suggest_lines_portrait">12</integer> <!-- The maximum number of open tabs --> diff --git a/src/com/android/browser/SuggestionsAdapter.java b/src/com/android/browser/SuggestionsAdapter.java index 260da6e..7ee5c2a 100644 --- a/src/com/android/browser/SuggestionsAdapter.java +++ b/src/com/android/browser/SuggestionsAdapter.java @@ -53,8 +53,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli {BrowserContract.Combined._ID, BrowserContract.Combined.TITLE, BrowserContract.Combined.URL, BrowserContract.Combined.IS_BOOKMARK}; - private static final String[] SEARCHES_PROJECTION = {BrowserContract.Searches.SEARCH}; - private static final String COMBINED_SELECTION = "(url LIKE ? OR url LIKE ? OR url LIKE ? OR url LIKE ? OR title LIKE ?)"; @@ -88,7 +86,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli mLinesLandscape = mContext.getResources(). getInteger(R.integer.max_suggest_lines_landscape); mFilter = new SuggestFilter(); - addSource(new SearchesCursor()); addSource(new CombinedCursor()); } @@ -102,14 +99,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli notifyDataSetChanged(); } - public int getLeftCount() { - return mMixedResults.getLeftCount(); - } - - public int getRightCount() { - return mMixedResults.getRightCount(); - } - public void addSource(CursorSource c) { if (mSources == null) { mSources = new ArrayList<CursorSource>(5); @@ -119,12 +108,11 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli @Override public void onClick(View v) { + SuggestItem item = (SuggestItem) ((View) v.getParent()).getTag(); if (R.id.icon2 == v.getId()) { // replace input field text with suggestion text - SuggestItem item = (SuggestItem) ((View) v.getParent()).getTag(); mListener.onSearch(item.title); } else { - SuggestItem item = (SuggestItem) v.getTag(); mListener.onSelect((TextUtils.isEmpty(item.url)? item.title : item.url), item.extra); } @@ -152,25 +140,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli if (mMixedResults == null) { return null; } - if (mLandscapeMode) { - if (position >= mMixedResults.getLineCount()) { - // right column - position = position - mMixedResults.getLineCount(); - // index in column - if (position >= mMixedResults.getRightCount()) { - return null; - } - return mMixedResults.items.get(position + mMixedResults.getLeftCount()); - } else { - // left column - if (position >= mMixedResults.getLeftCount()) { - return null; - } - return mMixedResults.items.get(position); - } - } else { - return mMixedResults.items.get(position); - } + return mMixedResults.items.get(position); } @Override @@ -183,35 +153,10 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli final LayoutInflater inflater = LayoutInflater.from(mContext); View view = convertView; if (view == null) { - view = inflater.inflate(R.layout.suggestion_two_column, parent, false); - } - View s1 = view.findViewById(R.id.suggest1); - View s2 = view.findViewById(R.id.suggest2); - View div = view.findViewById(R.id.suggestion_divider); - if (mLandscapeMode && (mVoiceResults == null)) { - SuggestItem item = getItem(position); - div.setVisibility(View.VISIBLE); - if (item != null) { - s1.setVisibility(View.VISIBLE); - bindView(s1, item); - } else { - s1.setVisibility(View.INVISIBLE); - } - item = getItem(position + mMixedResults.getLineCount()); - if (item != null) { - s2.setVisibility(View.VISIBLE); - bindView(s2, item); - } else { - s2.setVisibility(View.INVISIBLE); - } - return view; - } else { - s1.setVisibility(View.VISIBLE); - div.setVisibility(View.GONE); - s2.setVisibility(View.GONE); - bindView(s1, getItem(position)); - return view; + view = inflater.inflate(R.layout.suggestion_item, parent, false); } + bindView(view, getItem(position)); + return view; } private void bindView(View view, SuggestItem item) { @@ -220,11 +165,15 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli TextView tv1 = (TextView) view.findViewById(android.R.id.text1); TextView tv2 = (TextView) view.findViewById(android.R.id.text2); ImageView ic1 = (ImageView) view.findViewById(R.id.icon1); - View spacer = view.findViewById(R.id.spacer); View ic2 = view.findViewById(R.id.icon2); View div = view.findViewById(R.id.divider); tv1.setText(item.title); - tv2.setText(item.url); + if (TextUtils.isEmpty(item.url)) { + tv2.setVisibility(View.GONE); + } else { + tv2.setVisibility(View.VISIBLE); + tv2.setText(item.url); + } int id = -1; switch (item.type) { case TYPE_SUGGEST: @@ -249,10 +198,8 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli ic2.setVisibility(((TYPE_SUGGEST == item.type) || (TYPE_SEARCH == item.type)) ? View.VISIBLE : View.GONE); div.setVisibility(ic2.getVisibility()); - spacer.setVisibility(((TYPE_SUGGEST == item.type) || (TYPE_SEARCH == item.type)) - ? View.GONE : View.INVISIBLE); - view.setOnClickListener(this); ic2.setOnClickListener(this); + view.findViewById(R.id.suggestion).setOnClickListener(this); } class SlowFilterTask extends AsyncTask<CharSequence, Void, List<SuggestItem>> { @@ -350,7 +297,8 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli } void mixResults(List<SuggestItem> results) { - int maxLines = mLandscapeMode ? mLinesLandscape : (mLinesPortrait / 2); + int maxLines = mLandscapeMode ? mLinesLandscape : mLinesPortrait; + maxLines = (int) Math.ceil(maxLines / 2.0); for (int i = 0; i < mSources.size(); i++) { CursorSource s = mSources.get(i); int n = Math.min(s.getCount(), maxLines); @@ -404,21 +352,12 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli int getLineCount() { if (mLandscapeMode) { - return Math.min(mLinesLandscape, - Math.max(getLeftCount(), getRightCount())); + return Math.min(mLinesLandscape, items.size()); } else { - return Math.min(mLinesPortrait, getLeftCount() + getRightCount()); + return Math.min(mLinesPortrait, items.size()); } } - int getLeftCount() { - return counts[TYPE_BOOKMARK] + counts[TYPE_HISTORY] + counts[TYPE_SUGGEST_URL]; - } - - int getRightCount() { - return counts[TYPE_SEARCH] + counts[TYPE_SUGGEST]; - } - @Override public String toString() { if (items == null) return null; @@ -516,7 +455,7 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli } Uri.Builder ub = BrowserContract.Combined.CONTENT_URI.buildUpon(); ub.appendQueryParameter(BrowserContract.PARAM_LIMIT, - Integer.toString(mLinesPortrait)); + Integer.toString(Math.max(mLinesLandscape, mLinesPortrait))); BookmarkUtils.addAccountInfo(mContext, ub); mCursor = mContext.getContentResolver().query(ub.build(), COMBINED_PROJECTION, @@ -561,39 +500,6 @@ public class SuggestionsAdapter extends BaseAdapter implements Filterable, OnCli } } - class SearchesCursor extends CursorSource { - - @Override - public SuggestItem getItem() { - if ((mCursor != null) && (!mCursor.isAfterLast())) { - return new SuggestItem(mCursor.getString(0), null, TYPE_SEARCH); - } - return null; - } - - @Override - public void runQuery(CharSequence constraint) { - // constraint != null - if (mCursor != null) { - mCursor.close(); - } - String like = constraint + "%"; - String[] args = new String[] {like}; - String selection = BrowserContract.Searches.SEARCH + " LIKE ?"; - Uri.Builder ub = BrowserContract.Searches.CONTENT_URI.buildUpon(); - ub.appendQueryParameter(BrowserContract.PARAM_LIMIT, - Integer.toString(mLinesPortrait)); - mCursor = - mContext.getContentResolver().query(ub.build(), SEARCHES_PROJECTION, - selection, - args, BrowserContract.Searches.DATE + " DESC"); - if (mCursor != null) { - mCursor.moveToFirst(); - } - } - - } - class SuggestCursor extends CursorSource { @Override diff --git a/src/com/android/browser/UrlInputView.java b/src/com/android/browser/UrlInputView.java index 505662d..8aeef31 100644 --- a/src/com/android/browser/UrlInputView.java +++ b/src/com/android/browser/UrlInputView.java @@ -17,6 +17,7 @@ package com.android.browser; import com.android.browser.SuggestionsAdapter.CompletionListener; +import com.android.browser.SuggestionsAdapter.SuggestItem; import android.content.Context; import android.content.res.Configuration; @@ -26,6 +27,9 @@ import android.view.KeyEvent; import android.view.View; import android.view.View.OnFocusChangeListener; import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemSelectedListener; import android.widget.AutoCompleteTextView; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; @@ -38,7 +42,7 @@ import java.util.List; */ public class UrlInputView extends AutoCompleteTextView implements OnFocusChangeListener, OnEditorActionListener, - CompletionListener { + CompletionListener, OnItemClickListener { static final String TYPED = "browser-type"; @@ -76,6 +80,7 @@ public class UrlInputView extends AutoCompleteTextView setSelectAllOnFocus(true); onConfigurationChanged(ctx.getResources().getConfiguration()); setThreshold(1); + setOnItemClickListener(this); } void setController(UiController controller) { @@ -101,6 +106,7 @@ public class UrlInputView extends AutoCompleteTextView mAdapter.setLandscapeMode(mLandscape); if (isPopupShowing() && (getVisibility() == View.VISIBLE)) { setupDropDown(); + performFiltering(getText(), 0); } } @@ -204,4 +210,12 @@ public class UrlInputView extends AutoCompleteTextView } + @Override + public void onItemClick( + AdapterView<?> parent, View view, int position, long id) { + SuggestItem item = mAdapter.getItem(position); + onSelect((TextUtils.isEmpty(item.url) ? item.title : item.url), + item.extra); + } + } |