added edit search query button
This commit is contained in:
parent
12e4be008c
commit
fa21f99796
|
@ -327,7 +327,9 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||
text1.setText(mQuery);
|
||||
icon.setImageResource(R.drawable.ic_action_save);
|
||||
icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
|
||||
final View editQuery = view.findViewById(R.id.edit_query);
|
||||
editQuery.setTag(position);
|
||||
editQuery.setOnClickListener(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -340,6 +342,9 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
return ITEM_VIEW_TYPE;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return mQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(QuickSearchBarActivity activity, int position) {
|
||||
|
@ -363,13 +368,19 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
return mCursorId;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return mQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindView(SuggestionsAdapter adapter, View view, int position) {
|
||||
final ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
|
||||
final TextView text1 = (TextView) view.findViewById(android.R.id.text1);
|
||||
text1.setText(mQuery);
|
||||
icon.setImageResource(R.drawable.ic_action_history);
|
||||
icon.setColorFilter(text1.getCurrentTextColor(), Mode.SRC_ATOP);
|
||||
final View editQuery = view.findViewById(R.id.edit_query);
|
||||
editQuery.setTag(position);
|
||||
editQuery.setOnClickListener(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -388,20 +399,27 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
activity.finish();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class SuggestionsAdapter extends BaseAdapter {
|
||||
private void setSearchQuery(String query) {
|
||||
mSearchQuery.setText(query);
|
||||
if (query == null) return;
|
||||
mSearchQuery.setSelection(query.length());
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
public static class SuggestionsAdapter extends BaseAdapter implements OnClickListener {
|
||||
|
||||
private final QuickSearchBarActivity mActivity;
|
||||
private final LayoutInflater mInflater;
|
||||
private final MediaLoaderWrapper mImageLoader;
|
||||
private final UserColorNameManager mUserColorNameManager;
|
||||
private List<SuggestionItem> mData;
|
||||
|
||||
SuggestionsAdapter(Context context) {
|
||||
mContext = context;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
final TwidereApplication application = TwidereApplication.getInstance(context);
|
||||
SuggestionsAdapter(QuickSearchBarActivity activity) {
|
||||
mActivity = activity;
|
||||
mInflater = LayoutInflater.from(activity);
|
||||
final TwidereApplication application = TwidereApplication.getInstance(activity);
|
||||
mImageLoader = application.getMediaLoaderWrapper();
|
||||
mUserColorNameManager = application.getUserColorNameManager();
|
||||
}
|
||||
|
@ -411,7 +429,7 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
}
|
||||
|
||||
public Context getContext() {
|
||||
return mContext;
|
||||
return mActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -478,6 +496,21 @@ public class QuickSearchBarActivity extends ThemedFragmentActivity implements On
|
|||
public UserColorNameManager getUserColorNameManager() {
|
||||
return mUserColorNameManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.edit_query: {
|
||||
final SuggestionItem item = getItem((Integer) v.getTag());
|
||||
if (item instanceof SearchHistoryItem) {
|
||||
mActivity.setSearchQuery(((SearchHistoryItem) item).getQuery());
|
||||
} else if (item instanceof SavedSearchItem) {
|
||||
mActivity.setSearchQuery(((SavedSearchItem) item).getQuery());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuggestionsLoader extends AsyncTaskLoader<List<SuggestionItem>> {
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
public class SquareActionIconButton extends ActionIconButton {
|
||||
|
||||
public SquareActionIconButton(final Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public SquareActionIconButton(final Context context, final AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public SquareActionIconButton(final Context context, final AttributeSet attrs, final int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
|
||||
final int width = MeasureSpec.getSize(widthMeasureSpec), height = MeasureSpec.getSize(heightMeasureSpec);
|
||||
final ViewGroup.LayoutParams lp = getLayoutParams();
|
||||
if (lp.height == ViewGroup.LayoutParams.MATCH_PARENT && lp.width == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||
super.onMeasure(heightMeasureSpec, heightMeasureSpec);
|
||||
setMeasuredDimension(height, height);
|
||||
} else if (lp.width == ViewGroup.LayoutParams.MATCH_PARENT && lp.height == ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
|
||||
setMeasuredDimension(width, width);
|
||||
} else {
|
||||
if (width > height) {
|
||||
super.onMeasure(heightMeasureSpec, heightMeasureSpec);
|
||||
setMeasuredDimension(height, height);
|
||||
} else {
|
||||
super.onMeasure(widthMeasureSpec, widthMeasureSpec);
|
||||
setMeasuredDimension(width, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 428 B |
Binary file not shown.
After Width: | Height: | Size: 340 B |
Binary file not shown.
After Width: | Height: | Size: 441 B |
Binary file not shown.
After Width: | Height: | Size: 537 B |
Binary file not shown.
After Width: | Height: | Size: 556 B |
|
@ -21,27 +21,34 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/element_size_normal"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:listPreferredItemHeightSmall"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/element_spacing_small">
|
||||
|
||||
<org.mariotaku.twidere.view.SquareImageView
|
||||
<org.mariotaku.twidere.view.SquareActionIconButton
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:color="?menuIconColor"
|
||||
android:contentDescription="@string/icon"
|
||||
android:focusable="false"
|
||||
android:scaleType="centerInside"
|
||||
tools:src="@drawable/ic_action_search" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="0dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingLeft="@dimen/element_spacing_small"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingStart="@dimen/element_spacing_small">
|
||||
|
||||
<TextView
|
||||
|
@ -54,4 +61,16 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<org.mariotaku.twidere.view.SquareActionIconButton
|
||||
android:id="@+id/edit_query"
|
||||
android:layout_width="@dimen/element_size_normal"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0"
|
||||
android:background="?actionBarItemBackground"
|
||||
android:clickable="true"
|
||||
android:color="?menuIconColor"
|
||||
android:focusable="true"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_edit_query" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
|
||||
<!-- Generator: Sketch 3.3.1 (12005) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>Artboard 1</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs></defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
|
||||
<g id="Artboard-1" sketch:type="MSArtboardGroup" fill="#FFFFFF">
|
||||
<path d="M24,10.41 L22.59,9 L11,20.59 L11,14 L9,14 L9,24 L19,24 L19,22 L12.41,22 L24,10.41 Z" id="Shape" sketch:type="MSShapeGroup" transform="translate(16.500000, 16.500000) scale(1, -1) translate(-16.500000, -16.500000) "></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 874 B |
Loading…
Reference in New Issue