Let user search for image
This commit is contained in:
parent
91db03bc47
commit
85f1a86b5d
3 changed files with 54 additions and 9 deletions
|
@ -32,6 +32,9 @@ import android.graphics.Bitmap;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
@ -281,18 +284,43 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
|
|||
int marginSmall = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_small);
|
||||
int marginMedium = context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium);
|
||||
|
||||
final ThumbnailSelectionAdapter thumbnailAdapter = new ThumbnailSelectionAdapter(context);
|
||||
|
||||
final EditText input = new EditText(context);
|
||||
input.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
input.setSingleLine();
|
||||
|
||||
input.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
thumbnailAdapter.filter(editable.toString());
|
||||
}
|
||||
});
|
||||
|
||||
GridView grid = new GridView(context);
|
||||
grid.setAdapter(new ThumbnailSelectionAdapter(context));
|
||||
grid.setAdapter(thumbnailAdapter);
|
||||
grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size));
|
||||
grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size_small));
|
||||
grid.setNumColumns(GridView.AUTO_FIT);
|
||||
grid.setVerticalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium));
|
||||
grid.setHorizontalSpacing(context.getResources().getDimensionPixelSize(R.dimen.activity_margin_medium));
|
||||
grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
|
||||
|
||||
LinearLayout layout = new LinearLayout(context);
|
||||
layout.setOrientation(LinearLayout.VERTICAL);
|
||||
layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
layout.addView(input);
|
||||
layout.addView(grid);
|
||||
|
||||
FrameLayout container = new FrameLayout(context);
|
||||
container.setPaddingRelative(marginMedium, marginSmall, marginMedium, 0);
|
||||
container.addView(grid);
|
||||
container.addView(layout);
|
||||
|
||||
final AlertDialog alert = builder.setTitle(R.string.menu_popup_change_image)
|
||||
.setView(container)
|
||||
|
|
|
@ -15,36 +15,52 @@ import org.shadowice.flocke.andotp.R;
|
|||
import org.shadowice.flocke.andotp.Utilities.EntryThumbnail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ThumbnailSelectionAdapter extends BaseAdapter {
|
||||
private Context context;
|
||||
private List items;
|
||||
|
||||
ThumbnailSelectionAdapter(Context context) {
|
||||
items = new ArrayList(EntryThumbnail.EntryThumbnails.values().length);
|
||||
Collections.addAll(items, EntryThumbnail.EntryThumbnails.values());
|
||||
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
void filter(String filter) {
|
||||
items.clear();
|
||||
for (EntryThumbnail.EntryThumbnails thumb : EntryThumbnail.EntryThumbnails.values()) {
|
||||
if(thumb.name().toLowerCase().contains(filter.toLowerCase())) {
|
||||
items.add(thumb);
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return EntryThumbnail.EntryThumbnails.values().length;
|
||||
return items.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int i) {
|
||||
if(i >= EntryThumbnail.EntryThumbnails.values().length)
|
||||
return EntryThumbnail.EntryThumbnails.Default;
|
||||
if(i < getCount())
|
||||
return items.get(i);
|
||||
else
|
||||
return EntryThumbnail.EntryThumbnails.values()[i];
|
||||
return EntryThumbnail.EntryThumbnails.Default;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return EntryThumbnail.EntryThumbnails.values()[i].ordinal();
|
||||
return ((EntryThumbnail.EntryThumbnails) getItem(i)).ordinal();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getView(int i, View view, @NonNull ViewGroup viewGroup) {
|
||||
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size);
|
||||
int size = context.getResources().getDimensionPixelSize(R.dimen.card_thumbnail_size_small);
|
||||
ImageView imageView;
|
||||
if (view == null) {
|
||||
imageView = new ImageView(context);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<dimen name="card_corner_radius">0dp</dimen>
|
||||
<dimen name="card_thumbnail_size">64dp</dimen>
|
||||
<dimen name="card_thumbnail_size_small">46dp</dimen>
|
||||
|
||||
<!-- The default letter tile text size -->
|
||||
<dimen name="tile_letter_font_size">33sp</dimen>
|
||||
|
|
Loading…
Reference in a new issue