调整搜索记录提示
This commit is contained in:
1 parent
26a1e82c8d
commit
851eaeb201
3 files changed
+53
-13
No files matched your search
@@ -19,7 +19,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical" >
|
||||
android:orientation="vertical"
|
||||
android:focusableInTouchMode="true" >
|
||||
|
||||
<com.hippo.ehviewer.widget.CategoryTable
|
||||
android:id="@+id/category_table"
|
||||
@@ -43,7 +44,6 @@
|
||||
android:ems="10"
|
||||
android:hint="@string/hint_no_keyword"
|
||||
android:singleLine="true"
|
||||
android:dropDownVerticalOffset="38dp"
|
||||
android:textSize="@dimen/text_little_small" />
|
||||
|
||||
<CheckBox
|
||||
|
||||
@@ -67,7 +67,8 @@ public class SuggestionHelper extends SearchRecentSuggestions {
|
||||
@Override
|
||||
public void saveRecentQuery(final String queryString, final String line2) {
|
||||
super.saveRecentQuery(queryString, line2);
|
||||
mQueryList.add(0, queryString);
|
||||
if (!mQueryList.contains(queryString))
|
||||
mQueryList.add(0, queryString);
|
||||
truncateHistory(MAX_HISTORY_COUNT);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,13 @@ import java.util.List;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
|
||||
import com.hippo.ehviewer.util.ViewUtils;
|
||||
|
||||
public class SuggestionTextView extends PrefixEditText {
|
||||
|
||||
private static final String TAG = SuggestionTextView.class.getSimpleName();
|
||||
@@ -31,6 +35,8 @@ public class SuggestionTextView extends PrefixEditText {
|
||||
private List<String> mAllSuggestions;
|
||||
private ArrayAdapter<String> mAdapte;
|
||||
|
||||
private boolean mKeyboardIsShowing = true;
|
||||
|
||||
public SuggestionTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
@@ -43,14 +49,6 @@ public class SuggestionTextView extends PrefixEditText {
|
||||
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
|
||||
@@ -70,11 +68,52 @@ public class SuggestionTextView extends PrefixEditText {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (!isPopupShowing())
|
||||
showDropDown();
|
||||
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
// special case for the back key, we do not even try to send it
|
||||
// to the drop down list but instead, consume it immediately
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
|
||||
KeyEvent.DispatcherState state = getKeyDispatcherState();
|
||||
if (state != null) {
|
||||
state.startTracking(event, this);
|
||||
}
|
||||
return true;
|
||||
} else if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
KeyEvent.DispatcherState state = getKeyDispatcherState();
|
||||
if (state != null) {
|
||||
state.handleUpEvent(event);
|
||||
}
|
||||
if (event.isTracking() && !event.isCanceled()) {
|
||||
InputMethodManager imm = (InputMethodManager)
|
||||
getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null && mKeyboardIsShowing) {
|
||||
imm.hideSoftInputFromWindow(getWindowToken(), 0);
|
||||
mKeyboardIsShowing = false;
|
||||
} else {
|
||||
clearFocus();
|
||||
mKeyboardIsShowing = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onKeyPreIme(keyCode, event);
|
||||
}
|
||||
|
||||
public void setSuggestionHelper(SuggestionHelper helper) {
|
||||
if (helper != null) {
|
||||
mAllSuggestions = helper.getQueries();
|
||||
mAdapte = new ArrayAdapter<String>(getContext(),
|
||||
android.R.layout.simple_list_item_1, mAllSuggestions);
|
||||
mAdapte = new ArrayAdapter<String>(ViewUtils.sContextThemeWrapper,
|
||||
android.R.layout.simple_dropdown_item_1line, mAllSuggestions);
|
||||
setAdapter(mAdapte);
|
||||
} else {
|
||||
mAllSuggestions = null;
|
||||
|
||||
Reference in new issue
Block a user