搜索显示 suggestion
This commit is contained in:
1 parent
8ba3d11c11
commit
23225bdb56
7 files changed
+216
-38
No files matched your search
@@ -38,7 +38,7 @@
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="@string/checkbox_uploader" />
|
||||
|
||||
<com.hippo.ehviewer.widget.PrefixEditText
|
||||
<com.hippo.ehviewer.widget.SuggestionTextView
|
||||
android:id="@+id/search_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -47,8 +47,8 @@
|
||||
android:layout_marginRight="16dp"
|
||||
android:ems="10"
|
||||
android:hint="@string/hint_no_keyword"
|
||||
android:singleLine="true" >
|
||||
</com.hippo.ehviewer.widget.PrefixEditText>
|
||||
android:singleLine="true"
|
||||
android:dropDownVerticalOffset="38dp" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox_advance"
|
||||
|
||||
@@ -80,6 +80,7 @@ public class HttpHelper {
|
||||
private static final String DEFAULT_CHARSET = "utf-8";
|
||||
private static final String CHARSET_KEY = "charset=";
|
||||
|
||||
// TODO Get proxy list from server
|
||||
private static final String[] PROXY_URLS = {
|
||||
"http://proxyy0000.appsp0t.com/proxy",
|
||||
"http://proxyy0001.appsp0t.com/proxy",
|
||||
@@ -87,7 +88,16 @@ public class HttpHelper {
|
||||
"http://proxyy0003.appsp0t.com/proxy",
|
||||
"http://proxyy0004.appsp0t.com/proxy",
|
||||
"http://proxyy0005.appsp0t.com/proxy",
|
||||
"http://proxyy0006.appsp0t.com/proxy"
|
||||
"http://proxyy0006.appsp0t.com/proxy",
|
||||
"http://proxyy0007.appsp0t.com/proxy",
|
||||
"http://proxyy0008.appsp0t.com/proxy",
|
||||
"http://proxyy0009.appsp0t.com/proxy",
|
||||
"http://proxyy000a.appsp0t.com/proxy",
|
||||
"http://proxyy000b.appsp0t.com/proxy",
|
||||
"http://proxyy000c.appsp0t.com/proxy",
|
||||
"http://proxyy000d.appsp0t.com/proxy",
|
||||
"http://proxyy000e.appsp0t.com/proxy",
|
||||
"http://proxyy000f.appsp0t.com/proxy"
|
||||
};
|
||||
private static volatile int sProxyIndex = MathUtils.random(0, PROXY_URLS.length);
|
||||
private static Object sProxyIndexLock = new Object();
|
||||
|
||||
@@ -41,7 +41,6 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.SearchRecentSuggestions;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ImageSpan;
|
||||
@@ -93,8 +92,9 @@ import com.hippo.ehviewer.widget.CategoryTable;
|
||||
import com.hippo.ehviewer.widget.DialogBuilder;
|
||||
import com.hippo.ehviewer.widget.LoadImageView;
|
||||
import com.hippo.ehviewer.widget.MaterialToast;
|
||||
import com.hippo.ehviewer.widget.PrefixEditText;
|
||||
import com.hippo.ehviewer.widget.RatingView;
|
||||
import com.hippo.ehviewer.widget.SuggestionHelper;
|
||||
import com.hippo.ehviewer.widget.SuggestionTextView;
|
||||
import com.hippo.ehviewer.widget.SuperDialogUtil;
|
||||
import com.hippo.ehviewer.widget.TagListView;
|
||||
import com.hippo.ehviewer.widget.TagsAdapter;
|
||||
@@ -150,7 +150,7 @@ public class GalleryListActivity extends AbsGalleryActivity
|
||||
private EhClient mClient;
|
||||
private Resources mResources;
|
||||
private WindowsAnimate mWindowsAnimate;
|
||||
private SearchRecentSuggestions mSuggestions;
|
||||
private SuggestionHelper mSuggestions;
|
||||
|
||||
private SlidingMenu mSlidingMenu;
|
||||
private View mMenuLeft;
|
||||
@@ -314,16 +314,20 @@ public class GalleryListActivity extends AbsGalleryActivity
|
||||
}
|
||||
|
||||
private void handleSearchView(View view) {
|
||||
final PrefixEditText pet = (PrefixEditText)view.findViewById(R.id.search_text);
|
||||
final SuggestionTextView pet = (SuggestionTextView)view.findViewById(R.id.search_text);
|
||||
pet.setSuggestionHelper(mSuggestions);
|
||||
CheckBox uploaderCb = (CheckBox)view.findViewById(R.id.checkbox_uploader);
|
||||
uploaderCb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
if (isChecked)
|
||||
if (isChecked) {
|
||||
pet.setPrefix("uploader:");
|
||||
else
|
||||
pet.setSuggestionHelper(null);
|
||||
} else {
|
||||
pet.setPrefix(null);
|
||||
pet.setSuggestionHelper(mSuggestions);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -943,7 +947,7 @@ public class GalleryListActivity extends AbsGalleryActivity
|
||||
mResources = getResources();
|
||||
mWindowsAnimate = new WindowsAnimate();
|
||||
mWindowsAnimate.init(this);
|
||||
mSuggestions = new SearchRecentSuggestions(
|
||||
mSuggestions = SuggestionHelper.getInstance (
|
||||
GalleryListActivity.this, SimpleSuggestionProvider.AUTHORITY,
|
||||
SimpleSuggestionProvider.MODE);
|
||||
|
||||
@@ -1445,18 +1449,6 @@ public class GalleryListActivity extends AbsGalleryActivity
|
||||
super.onDestroy();
|
||||
unbindService(mServiceConn);
|
||||
|
||||
/*
|
||||
List<GalleryInfo> reads = mData.getAllReads();
|
||||
for (GalleryInfo item : reads) {
|
||||
File folder = new File(Config.getDownloadPath(),
|
||||
StringEscapeUtils.escapeHtml4(item.title));
|
||||
try {
|
||||
Util.deleteContents(folder);
|
||||
folder.delete();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
mWindowsAnimate.free();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ import com.hippo.ehviewer.widget.DialogBuilder;
|
||||
import com.hippo.ehviewer.widget.FileExplorerView;
|
||||
import com.hippo.ehviewer.widget.MaterialToast;
|
||||
import com.hippo.ehviewer.widget.ProgressDialogBulider;
|
||||
import com.hippo.ehviewer.widget.SuggestionHelper;
|
||||
import com.hippo.ehviewer.widget.SuperDialogUtil;
|
||||
|
||||
public class SettingsActivity extends AbsPreferenceActivity {
|
||||
@@ -410,8 +411,9 @@ public class SettingsActivity extends AbsPreferenceActivity {
|
||||
}).create().show();
|
||||
|
||||
} else if (KEY_CLEAR_SUGGESTIONS.equals(key)) {
|
||||
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(mActivity,
|
||||
SimpleSuggestionProvider.AUTHORITY, SimpleSuggestionProvider.MODE);
|
||||
SearchRecentSuggestions suggestions = SuggestionHelper.getInstance (
|
||||
mActivity, SimpleSuggestionProvider.AUTHORITY,
|
||||
SimpleSuggestionProvider.MODE);
|
||||
suggestions.clearHistory();
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -21,14 +21,14 @@ import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.EditText;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
|
||||
public class PrefixEditText extends EditText
|
||||
public class PrefixEditText extends AutoCompleteTextView
|
||||
implements TextWatcher {
|
||||
|
||||
|
||||
private Context mContext;
|
||||
private String mPrefix;
|
||||
|
||||
|
||||
public PrefixEditText(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
@@ -41,24 +41,24 @@ public class PrefixEditText extends EditText
|
||||
super(context, attrs, defStyle);
|
||||
init(context);
|
||||
}
|
||||
|
||||
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
addTextChangedListener(this);
|
||||
}
|
||||
|
||||
|
||||
public void setPrefix(int resId) {
|
||||
setPrefix(mContext.getString(resId));
|
||||
}
|
||||
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
mPrefix = prefix;
|
||||
setText(mPrefix);
|
||||
if (mPrefix != null)
|
||||
Selection.setSelection(getText(), mPrefix.length());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Override
|
||||
protected void onSelectionChanged(int selStart, int selEnd) {
|
||||
super.onSelectionChanged(selStart, selEnd);
|
||||
if(mPrefix != null) {
|
||||
@@ -72,15 +72,15 @@ public class PrefixEditText extends EditText
|
||||
setSelection(newSelStart, newSelEnd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,
|
||||
int after) {}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start,
|
||||
int before, int count) {}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if(mPrefix != null &&
|
||||
@@ -89,5 +89,5 @@ public class PrefixEditText extends EditText
|
||||
setSelection(mPrefix.length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Hippo Seven
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.SearchRecentSuggestions;
|
||||
|
||||
public class SuggestionHelper extends SearchRecentSuggestions {
|
||||
|
||||
private static final String QUERY = "query";
|
||||
private static final String ORDER_BY = "date DESC";
|
||||
|
||||
private static final int MAX_HISTORY_COUNT = 250;
|
||||
|
||||
private final List<String> mQueryList = new ArrayList<String>();
|
||||
|
||||
private static Map<String, SuggestionHelper> sInstances = new HashMap<String, SuggestionHelper>();
|
||||
|
||||
public static SuggestionHelper getInstance(Context context, String authority, int mode) {
|
||||
SuggestionHelper s = sInstances.get(authority);
|
||||
if (s == null) {
|
||||
s = new SuggestionHelper(context, authority, mode);
|
||||
sInstances.put(authority, s);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private SuggestionHelper(Context context, String authority, int mode) {
|
||||
super(context, authority, mode);
|
||||
|
||||
Uri suggestionsUri = Uri.parse("content://" + authority + "/suggestions");
|
||||
|
||||
// Get all suggestion
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
Cursor cursor = cr.query(suggestionsUri, new String[]{QUERY}, null, null, ORDER_BY);
|
||||
while(cursor.moveToNext())
|
||||
mQueryList.add(cursor.getString(cursor.getColumnIndex(QUERY)));
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
public List<String> getQueries() {
|
||||
return mQueryList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveRecentQuery(final String queryString, final String line2) {
|
||||
super.saveRecentQuery(queryString, line2);
|
||||
mQueryList.add(0, queryString);
|
||||
truncateHistory(MAX_HISTORY_COUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHistory() {
|
||||
super.clearHistory();
|
||||
truncateHistory(0);
|
||||
}
|
||||
|
||||
private void truncateHistory(int maxEntries) {
|
||||
if (maxEntries == 0) {
|
||||
mQueryList.clear();
|
||||
} else {
|
||||
for (int i = mQueryList.size() - 1; i >= maxEntries; i--) {
|
||||
mQueryList.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Hippo Seven
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
|
||||
public class SuggestionTextView extends PrefixEditText {
|
||||
|
||||
private static final String TAG = SuggestionTextView.class.getSimpleName();
|
||||
|
||||
private List<String> mAllSuggestions;
|
||||
private ArrayAdapter<String> mAdapte;
|
||||
|
||||
public SuggestionTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SuggestionTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SuggestionTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* We override this method to avoid replacing the query box text when a
|
||||
* suggestion is clicked.
|
||||
*/
|
||||
@Override
|
||||
protected void replaceText(CharSequence text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* We override this method to avoid an extra onItemClick being called on
|
||||
* the drop-down's OnItemClickListener by
|
||||
* {@link AutoCompleteTextView#onKeyUp(int, KeyEvent)} when an item is
|
||||
* clicked with the trackball.
|
||||
*/
|
||||
@Override
|
||||
public void performCompletion() {
|
||||
}
|
||||
|
||||
/**
|
||||
* We override this method so that we can allow a threshold of zero,
|
||||
* which ACTV does not.
|
||||
*/
|
||||
@Override
|
||||
public boolean enoughToFilter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setSuggestionHelper(SuggestionHelper helper) {
|
||||
if (helper != null) {
|
||||
mAllSuggestions = helper.getQueries();
|
||||
mAdapte = new ArrayAdapter<String>(getContext(),
|
||||
android.R.layout.simple_list_item_1, mAllSuggestions);
|
||||
setAdapter(mAdapte);
|
||||
} else {
|
||||
mAllSuggestions = null;
|
||||
mAdapte = null;
|
||||
setAdapter(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user