Search in sources :

Example 1 with BaseItemLayoutAdapter

use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.

the class DragingDialogs method searchMenu.

public static void searchMenu(final FrameLayout anchor, final DocumentController controller, final String text) {
    DragingPopup dialog = new DragingPopup(R.string.search, anchor, 250, 150) {

        @Override
        public View getContentView(LayoutInflater inflater) {
            final View view = inflater.inflate(R.layout.search_dialog, null, false);
            final EditText searchEdit = (EditText) view.findViewById(R.id.edit1);
            searchEdit.setText(text);
            final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progressBar1);
            final TextView searchingMsg = (TextView) view.findViewById(R.id.searching);
            final GridView gridView = (GridView) view.findViewById(R.id.grid1);
            gridView.setColumnWidth(Dips.dpToPx(80));
            final BaseItemLayoutAdapter<Integer> adapter = new BaseItemLayoutAdapter<Integer>(anchor.getContext(), android.R.layout.simple_spinner_dropdown_item) {

                @Override
                public void populateView(View inflate, int arg1, Integer page) {
                    final TextView text = Views.text(inflate, android.R.id.text1, TxtUtils.deltaPage(page + 1, 0));
                    text.setGravity(Gravity.CENTER);
                    text.setTypeface(Typeface.DEFAULT, Typeface.BOLD);
                }

                @Override
                public long getItemId(int position) {
                    return getItem(position) + 1;
                }
            };
            gridView.setAdapter(adapter);
            gridView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    controller.onGoToPage((int) id);
                }
            });
            ImageView onClear = (ImageView) view.findViewById(R.id.imageClear);
            onClear.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    boolean isRun = TempHolder.isSeaching;
                    TempHolder.isSeaching = false;
                    if (!isRun) {
                        searchEdit.setText("");
                        controller.clearSelectedText();
                        searchingMsg.setVisibility(View.GONE);
                        adapter.getItems().clear();
                        adapter.notifyDataSetChanged();
                    }
                }
            });
            final View onSearch = view.findViewById(R.id.onSearch);
            TintUtil.setTintBg(onSearch);
            EditTextHelper.enableKeyboardSearch(searchEdit, new Runnable() {

                @Override
                public void run() {
                    onSearch.performClick();
                }
            });
            if (TxtUtils.isNotEmpty(text)) {
                onSearch.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        onSearch.performClick();
                    }
                }, 250);
            }
            final String searchingString = anchor.getContext().getString(R.string.searching_please_wait_);
            final int count = controller.getPageCount();
            final Handler hMessage = new Handler() {

                @Override
                public void handleMessage(android.os.Message msg) {
                    int pageNumber = msg.what;
                    LOG.d("Receive page", pageNumber);
                    progressBar.setVisibility(View.GONE);
                    gridView.setVisibility(View.VISIBLE);
                    if (pageNumber < -1) {
                        searchingMsg.setVisibility(View.VISIBLE);
                        searchingMsg.setText(searchingString + " " + Math.abs(pageNumber) + "/" + count);
                        return;
                    }
                    if (pageNumber == -1) {
                        if (adapter.getItems().size() == 0) {
                            searchingMsg.setVisibility(View.VISIBLE);
                            searchingMsg.setText(R.string.msg_no_text_found);
                        } else {
                            searchingMsg.setVisibility(View.GONE);
                        }
                    }
                    if (pageNumber == Integer.MAX_VALUE) {
                        adapter.notifyDataSetChanged();
                        return;
                    }
                    if (pageNumber >= 0) {
                        pageNumber = PageUrl.realToFake(pageNumber);
                        searchingMsg.setVisibility(View.VISIBLE);
                        adapter.getItems().add(pageNumber);
                        adapter.notifyDataSetChanged();
                    }
                }
            };
            onSearch.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (TempHolder.isSeaching) {
                        return;
                    }
                    String searchString = searchEdit.getText().toString().trim();
                    if (searchString.length() < 2) {
                        return;
                    }
                    TempHolder.isSeaching = true;
                    searchingMsg.setText(R.string.searching_please_wait_);
                    searchingMsg.setVisibility(View.VISIBLE);
                    progressBar.setVisibility(View.VISIBLE);
                    gridView.setVisibility(View.GONE);
                    adapter.getItems().clear();
                    adapter.notifyDataSetChanged();
                    Keyboards.close(searchEdit);
                    hMessage.removeCallbacksAndMessages(null);
                    controller.doSearch(searchString, new ResultResponse<Integer>() {

                        @Override
                        public boolean onResultRecive(final Integer pageNumber) {
                            hMessage.sendEmptyMessage(pageNumber);
                            return false;
                        }
                    });
                }
            });
            return view;
        }
    };
    dialog.setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            TempHolder.isSeaching = false;
        }
    });
    dialog.show("searchMenu");
}
Also used : EditText(android.widget.EditText) ResultResponse(com.foobnix.android.utils.ResultResponse) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) InvalidateMessage(com.foobnix.pdf.search.activity.msg.InvalidateMessage) Handler(android.os.Handler) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) GridView(android.widget.GridView) ImageView(android.widget.ImageView) ProgressBar(android.widget.ProgressBar) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Example 2 with BaseItemLayoutAdapter

use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.

the class MultyDocSearchDialog method getDialogView.

public static View getDialogView(final FragmentActivity c) {
    View inflate = LayoutInflater.from(c).inflate(R.layout.dialog_multy_search, null, false);
    inflate.setKeepScreenOn(true);
    final EditText editPath = (EditText) inflate.findViewById(R.id.editPath);
    final Button buttonPath = (Button) inflate.findViewById(R.id.buttonPath);
    final EditText editSearchText = (EditText) inflate.findViewById(R.id.editSearchText);
    final Button searchStart = (Button) inflate.findViewById(R.id.searchStart);
    final Button searchStop = (Button) inflate.findViewById(R.id.searchStop);
    infoView1 = (TextView) inflate.findViewById(R.id.infoView1);
    final ListView listView = (ListView) inflate.findViewById(R.id.listView);
    final CheckBox searchInTheSubfolders = (CheckBox) inflate.findViewById(R.id.searchInTheSubfolders);
    final BaseItemLayoutAdapter adapter = new BaseItemLayoutAdapter<Pair<String, Integer>>(c, android.R.layout.simple_list_item_1, Model.get().res) {

        @Override
        public void populateView(View layout, int position, final Pair<String, Integer> item) {
            final File file = new File(item.first);
            TextView t = (TextView) layout.findViewById(android.R.id.text1);
            t.setText(file.getName() + " [" + (item.second == -1 ? "not found" : (item.second + 1)) + "]");
            t.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    ExtUtils.showDocument(c, file, item.second + 1);
                }
            });
        }
    };
    listView.setAdapter(adapter);
    buttonPath.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ChooserDialogFragment.chooseFolder(c, Model.get().path).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                @Override
                public boolean onResultRecive(String nPath, Dialog dialog) {
                    Model.get().path = nPath;
                    AppState.get().dirLastPath = nPath;
                    editPath.setText(Model.get().path);
                    dialog.dismiss();
                    return false;
                }
            });
        }
    });
    editPath.setText(Model.get().path);
    final Handler updater2 = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            adapter.notifyDataSetChanged();
        }
    };
    final Handler updater1 = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            infoView1.setText((Model.get().currentPage + 1) + "/" + Model.get().currentPagesCount + " " + Model.get().currentDoc);
        }
    };
    searchStart.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Model.get().text = editSearchText.getText().toString().trim();
            if (TxtUtils.isEmpty(Model.get().text)) {
                Toast.makeText(c, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                return;
            }
            if (Model.get().text.contains(" ")) {
                Toast.makeText(c, R.string.you_can_search_only_one_word, Toast.LENGTH_SHORT).show();
                return;
            }
            if (Model.get().isSearcingRun) {
                Toast.makeText(c, R.string.searching_please_wait_, Toast.LENGTH_SHORT).show();
                return;
            }
            Model.get().isSearcingRun = true;
            new MyTask(updater1, updater2, c, searchInTheSubfolders.isChecked()).execute();
            infoView1.setText("");
            Model.get().res.clear();
            adapter.notifyDataSetChanged();
            Keyboards.close(editSearchText);
        }
    });
    editSearchText.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                searchStart.performClick();
                handled = true;
            }
            return handled;
        }
    });
    editSearchText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                searchStart.performClick();
                return true;
            }
            return false;
        }
    });
    searchStop.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Model.get().isSearcingRun = false;
            infoView1.setText("");
        }
    });
    infoView1.setText("");
    Model.get().res.clear();
    adapter.notifyDataSetChanged();
    return inflate;
}
Also used : EditText(android.widget.EditText) ResultResponse2(com.foobnix.android.utils.ResultResponse2) Message(android.os.Message) Handler(android.os.Handler) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) KeyEvent(android.view.KeyEvent) ListView(android.widget.ListView) Button(android.widget.Button) CheckBox(android.widget.CheckBox) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) OnClickListener(android.view.View.OnClickListener) OnKeyListener(android.view.View.OnKeyListener) TextView(android.widget.TextView) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter) File(java.io.File) Pair(android.support.v4.util.Pair)

Example 3 with BaseItemLayoutAdapter

use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.

the class TapZoneDialog method show.

public static void show(final Context c) {
    final View inflate = LayoutInflater.from(c).inflate(R.layout.dialog_tap_zone, null, false);
    final List<String> items = Arrays.asList(c.getString(R.string.next_page), c.getString(R.string.previous_page), c.getString(R.string.db_do_nothing));
    final BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(c, android.R.layout.simple_spinner_dropdown_item, items) {

        @Override
        public void populateView(View inflate, int arg1, String value) {
            Views.text(inflate, android.R.id.text1, "" + value);
        }

        @Override
        public String getItem(int position) {
            return items.get(position);
        }
    };
    final Spinner leftSide = (Spinner) inflate.findViewById(R.id.leftSide);
    final Spinner rightSide = (Spinner) inflate.findViewById(R.id.rightSide);
    final Spinner topSide = (Spinner) inflate.findViewById(R.id.topSide);
    final Spinner bottomSide = (Spinner) inflate.findViewById(R.id.bottomSide);
    leftSide.setAdapter(adapter);
    rightSide.setAdapter(adapter);
    topSide.setAdapter(adapter);
    bottomSide.setAdapter(adapter);
    leftSide.setSelection(AppState.get().tapZoneLeft, false);
    rightSide.setSelection(AppState.get().tapZoneRight, false);
    topSide.setSelection(AppState.get().tapZoneTop, false);
    bottomSide.setSelection(AppState.get().tapZoneBottom, false);
    final AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setTitle(R.string.customize_tap_zones);
    builder.setView(inflate);
    builder.setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            AppState.get().tapZoneLeft = leftSide.getSelectedItemPosition();
            AppState.get().tapZoneRight = rightSide.getSelectedItemPosition();
            AppState.get().tapZoneTop = topSide.getSelectedItemPosition();
            AppState.get().tapZoneBottom = bottomSide.getSelectedItemPosition();
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) View(android.view.View) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Example 4 with BaseItemLayoutAdapter

use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.

the class ZipDialog method getDialogContent.

public static View getDialogContent(final Activity a, final Uri uri, final Runnable onDismiss) {
    final List<String> items = new ArrayList<String>();
    BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(a, R.layout.zip_item, items) {

        @Override
        public void populateView(View layout, int position, String item) {
            TextView text = (TextView) layout.findViewById(R.id.text1);
            text.setText(item);
        }
    };
    ListView list = new ListView(a);
    try {
        InputStream openInputStream = getStream(a, uri);
        ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(openInputStream, CP1251, true);
        ZipArchiveEntry nextEntry = null;
        while ((nextEntry = zipInputStream.getNextZipEntry()) != null) {
            String nameFull = nextEntry.getName();
            LOG.d(nameFull);
            if (!nextEntry.isDirectory()) {
                items.add(nameFull);
            }
        }
        zipInputStream.close();
        openInputStream.close();
    } catch (Exception e) {
        LOG.e(e);
    }
    list.setAdapter(adapter);
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            String name = items.get(position);
            extractAsyncProccess(a, name, uri, onDismiss, false);
        }
    });
    adapter.notifyDataSetChanged();
    return list;
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) FileInputStream(java.io.FileInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) TextView(android.widget.TextView) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Example 5 with BaseItemLayoutAdapter

use of com.foobnix.android.utils.BaseItemLayoutAdapter in project LibreraReader by foobnix.

the class SearchFragment2 method showAutoCompleteDialog.

public void showAutoCompleteDialog() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.search_history_and_autocomplete);
    final ListView list = new ListView(getActivity());
    final List<String> items = new ArrayList<String>(AppState.get().myAutoComplete);
    Collections.sort(items);
    BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(getActivity(), R.layout.path_item, items) {

        @Override
        public void populateView(View layout, int position, final String item) {
            TextView text = layout.findViewById(R.id.browserPath);
            ImageView delete = layout.findViewById(R.id.delete);
            text.setText(item);
            delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    autocomplitions.remove(item);
                    items.remove(item);
                    AppState.get().myAutoComplete.remove(item);
                    notifyDataSetChanged();
                }
            });
            layout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchEditText.setText(item);
                    searchAndOrderAsync();
                }
            });
        }
    };
    list.setAdapter(adapter);
    builder.setView(list);
    builder.setPositiveButton(R.string.close, new AlertDialog.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    AlertDialog create = builder.create();
    create.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.hideNavigation(getActivity());
        }
    });
    create.show();
    Keyboards.close(getActivity());
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) ArrayList(java.util.ArrayList) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) RecyclerView(android.support.v7.widget.RecyclerView) ListView(android.widget.ListView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) ImageView(android.widget.ImageView) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter)

Aggregations

View (android.view.View)8 BaseItemLayoutAdapter (com.foobnix.android.utils.BaseItemLayoutAdapter)8 TextView (android.widget.TextView)7 ListView (android.widget.ListView)6 OnClickListener (android.view.View.OnClickListener)5 ImageView (android.widget.ImageView)5 AlertDialog (android.app.AlertDialog)4 DialogInterface (android.content.DialogInterface)3 RecyclerView (android.support.v7.widget.RecyclerView)3 AdapterView (android.widget.AdapterView)3 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)3 ArrayList (java.util.ArrayList)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 OnDismissListener (android.content.DialogInterface.OnDismissListener)2 Handler (android.os.Handler)2 LayoutInflater (android.view.LayoutInflater)2 AbsListView (android.widget.AbsListView)2 CheckBox (android.widget.CheckBox)2 EditText (android.widget.EditText)2