Search in sources :

Example 11 with MyPopupMenu

use of com.foobnix.pdf.info.view.MyPopupMenu in project LibreraReader by foobnix.

the class BrowseFragment2 method onCreateView.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_browse2, container, false);
    Bundle arguments = getArguments();
    pathContainer = view.findViewById(R.id.pathContainer);
    View onCloseActionPaner = view.findViewById(R.id.onCloseActionPaner);
    onClose = view.findViewById(R.id.onClose);
    starIcon = (ImageView) view.findViewById(R.id.starIcon);
    onSort = (ImageView) view.findViewById(R.id.onSort);
    onSort.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            AppState.get().sortByReverse = !AppState.get().sortByReverse;
            onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
            populate();
            return true;
        }
    });
    onSort.setImageResource(AppState.get().sortByReverse ? R.drawable.glyphicons_410_sort_by_attributes_alt : R.drawable.glyphicons_409_sort_by_attributes);
    onAction = view.findViewById(R.id.onAction);
    editPath = (EditText) view.findViewById(R.id.editPath);
    fragmentType = TYPE_DEFAULT;
    if (arguments != null) {
        fragmentType = arguments.getInt(EXTRA_TYPE, TYPE_DEFAULT);
        fragmentText = arguments.getString(EXTRA_TEXT);
        editPath.setText(fragmentText);
    }
    onClose.setOnClickListener(onCloseButtonActoin);
    onAction.setOnClickListener(onSelectAction);
    if (TYPE_DEFAULT == fragmentType) {
        editPath.setVisibility(View.GONE);
        onCloseActionPaner.setVisibility(View.GONE);
    }
    if (TYPE_SELECT_FOLDER == fragmentType) {
        editPath.setVisibility(View.VISIBLE);
        editPath.setEnabled(false);
        onCloseActionPaner.setVisibility(View.VISIBLE);
    }
    if (TYPE_SELECT_FILE == fragmentType) {
        editPath.setVisibility(View.VISIBLE);
        editPath.setEnabled(false);
        onCloseActionPaner.setVisibility(View.VISIBLE);
    }
    if (TYPE_CREATE_FILE == fragmentType) {
        editPath.setVisibility(View.VISIBLE);
        editPath.setEnabled(true);
        onCloseActionPaner.setVisibility(View.VISIBLE);
    }
    View onBack = view.findViewById(R.id.onBack);
    recyclerView = (FastScrollRecyclerView) view.findViewById(R.id.recyclerView);
    paths = (LinearLayout) view.findViewById(R.id.paths);
    scroller = (HorizontalScrollView) view.findViewById(R.id.scroller);
    final View onHome = view.findViewById(R.id.onHome);
    onListGrid = (ImageView) view.findViewById(R.id.onListGrid);
    onListGrid.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popupMenu(onListGrid);
        }
    });
    searchAdapter = new FileMetaAdapter();
    bindAdapter(searchAdapter);
    bindAuthorsSeriesAdapter(searchAdapter);
    onGridList();
    onHome.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            List<String> extFolders = new ArrayList<String>();
            extFolders = ExtUtils.getExternalStorageDirectories(getActivity());
            String sdPath = ExtUtils.getSDPath();
            if (TxtUtils.isNotEmpty(sdPath) && !extFolders.contains(sdPath)) {
                extFolders.add(sdPath);
            }
            MyPopupMenu menu = new MyPopupMenu(getActivity(), onHome);
            menu.getMenu().add(R.string.internal_storage).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    setDirPath(Environment.getExternalStorageDirectory().getPath());
                    return false;
                }
            }).setIcon(R.drawable.glyphicons_146_folder_sd1);
            for (final String info : extFolders) {
                String name;
                if (ExtUtils.isExteralSD(info)) {
                    name = ExtUtils.getExtSDDisplayName(getContext(), info);
                } else {
                    name = new File(info).getName();
                }
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        setDirPath(info);
                        return false;
                    }
                }).setIcon(R.drawable.glyphicons_146_folder_sd1);
            }
            menu.getMenu().add("Librera").setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    setDirPath(AppState.get().downlodsPath);
                    return false;
                }
            }).setIcon(R.drawable.glyphicons_591_folder_heart);
            if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
                List<String> safs = StringDB.asList(AppState.get().pathSAF);
                for (final String saf : safs) {
                    String fileName = DocumentsContract.getTreeDocumentId(Uri.parse(saf));
                    menu.getMenu().add(fileName).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            setDirPath(saf);
                            return false;
                        }
                    }).setOnMenuItemLongClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().pathSAF = StringDB.delete(AppState.get().pathSAF, saf);
                            return false;
                        }
                    }).setIcon(R.drawable.glyphicons_146_folder_plus);
                }
            }
            // stars
            List<FileMeta> starFolders = AppDB.get().getStarsFolder();
            List<String> names = new ArrayList<String>();
            for (FileMeta f : starFolders) {
                names.add(f.getPath());
            }
            Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
            for (final String info : names) {
                String name;
                if (ExtUtils.isExteralSD(info)) {
                    name = ExtUtils.getExtSDDisplayName(getContext(), info);
                } else {
                    name = new File(info).getName();
                }
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        setDirPath(info);
                        return false;
                    }
                }).setIcon(R.drawable.glyphicons_591_folder_star);
            }
            if (Build.VERSION.SDK_INT >= 21 && getActivity() instanceof MainTabs2) {
                menu.getMenu().add(R.string.add_resource).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                        intent.addFlags(// 
                        Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | // 
                        Intent.FLAG_GRANT_PREFIX_URI_PERMISSION | // 
                        Intent.FLAG_GRANT_READ_URI_PERMISSION | // 
                        Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                        getActivity().startActivityForResult(intent, MainTabs2.REQUEST_CODE_ADD_RESOURCE);
                        return true;
                    }
                }).setIcon(R.drawable.glyphicons_146_add_folder_plus);
            }
            menu.show();
        }
    });
    onBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackAction();
        }
    });
    searchAdapter.setOnItemClickListener(new ResultResponse<FileMeta>() {

        @Override
        public boolean onResultRecive(FileMeta result) {
            if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
                setDirPath(result.getPath());
                if (fragmentType == TYPE_SELECT_FOLDER) {
                    editPath.setText(fragmentText);
                }
            } else {
                if (fragmentType == TYPE_DEFAULT) {
                    DefaultListeners.getOnItemClickListener(getActivity()).onResultRecive(result);
                } else if (fragmentType == TYPE_SELECT_FILE) {
                    editPath.setText(ExtUtils.getFileName(result.getPath()));
                }
            }
            return false;
        }
    });
    searchAdapter.setOnItemLongClickListener(new ResultResponse<FileMeta>() {

        @Override
        public boolean onResultRecive(FileMeta result) {
            if (result.getCusType() != null && result.getCusType() == FileMetaAdapter.DISPLAY_TYPE_DIRECTORY) {
            // setDirPath(result.getPath());
            } else {
                DefaultListeners.getOnItemLongClickListener(getActivity(), searchAdapter).onResultRecive(result);
            }
            return false;
        }
    });
    onSort.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            List<String> names = // 
            Arrays.asList(// 
            getActivity().getString(R.string.by_file_name), // 
            getActivity().getString(R.string.by_date), // 
            getActivity().getString(R.string.by_size), // 
            getActivity().getString(R.string.by_title), // 
            getActivity().getString(R.string.by_number_in_serie), // 
            getActivity().getString(R.string.by_number_of_pages), // 
            getActivity().getString(R.string.by_extension));
            // 
            final List<Integer> ids = // 
            Arrays.asList(// 
            AppState.BR_SORT_BY_PATH, // 
            AppState.BR_SORT_BY_DATE, // 
            AppState.BR_SORT_BY_SIZE, // 
            AppState.BR_SORT_BY_TITLE, // 
            AppState.BR_SORT_BY_NUMBER, // 
            AppState.BR_SORT_BY_PAGES, // 
            AppState.BR_SORT_BY_EXT);
            // 
            MyPopupMenu menu = new MyPopupMenu(getActivity(), v);
            for (int i = 0; i < names.size(); i++) {
                String name = names.get(i);
                final int j = i;
                menu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().sortByBrowse = ids.get(j);
                        populate();
                        return false;
                    }
                });
            }
            menu.show();
        }
    });
    populate();
    onTintChanged();
    return view;
}
Also used : MainTabs2(com.foobnix.ui2.MainTabs2) Bundle(android.os.Bundle) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) MenuItem(android.view.MenuItem) Intent(android.content.Intent) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) FileMetaAdapter(com.foobnix.ui2.adapter.FileMetaAdapter) FileMeta(com.foobnix.dao2.FileMeta) TargetApi(android.annotation.TargetApi)

Example 12 with MyPopupMenu

use of com.foobnix.pdf.info.view.MyPopupMenu in project LibreraReader by foobnix.

the class CloseAppDialog method showOnLongClickDialog.

public static void showOnLongClickDialog(final Activity a, View v, final DocumentController c) {
    List<String> items = new ArrayList<String>();
    // 
    items.add(c.getString(R.string.close_book));
    // 
    items.add(c.getString(R.string.go_to_the_library));
    // 
    items.add(c.getString(R.string.hide_app));
    // 
    items.add(c.getString(R.string.close_application));
    final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            TTSNotification.hideNotification();
            TTSEngine.get().shutdown();
            int i = 0;
            if (which == i++) {
                c.onCloseActivityAdnShowInterstial();
            } else if (which == i++) {
                c.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        MainTabs2.startActivity(a, UITab.getCurrentTabIndex(UITab.SearchFragment));
                    }
                });
            } else if (which == i++) {
                Apps.showDesctop(a);
            } else if (which == i++) {
                c.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        MainTabs2.closeApp(a);
                    }
                });
            }
        }
    };
    if (v == null) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(a);
        dialog.setItems(items.toArray(new String[items.size()]), listener);
        // dialog.setNegativeButton(R.string.don_t_show_this_dialog, new
        // OnClickListener() {
        // 
        // @Override
        // public void onClick(DialogInterface dialog, int which) {
        // AppState.get().isShowLongBackDialog = false;
        // c.onCloseActivity();
        // dialog.dismiss();
        // }
        // });
        dialog.setPositiveButton(R.string.cancel, new OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();
    } else {
        final MyPopupMenu popupMenu = new MyPopupMenu(a, v);
        for (int i = 0; i < items.size(); i++) {
            final int j = i;
            popupMenu.getMenu().add(items.get(i)).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    listener.onClick(null, j);
                    return false;
                }
            });
        }
        popupMenu.show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ArrayList(java.util.ArrayList) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) MenuItem(android.view.MenuItem) OnClickListener(android.content.DialogInterface.OnClickListener) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 13 with MyPopupMenu

use of com.foobnix.pdf.info.view.MyPopupMenu in project LibreraReader by foobnix.

the class FontDialog method initSpinner.

public static void initSpinner(final View inflate, final TextView spinner, String path, int plusRes, int minusRes, int sampleRes) {
    final List<String> allFonts = BookCSS.get().getAllFonts();
    updateTextTag(spinner, path);
    spinner.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            MyPopupMenu menu = new MyPopupMenu(v.getContext(), v);
            for (final String fontPath : allFonts) {
                final String name = ExtUtils.getFileName(fontPath);
                menu.getMenu().add(name, fontPath).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        updateTextTag(spinner, fontPath);
                        return false;
                    }
                });
            }
            menu.show(getItemPos(spinner));
        }
    });
    inflate.findViewById(minusRes).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int index = getItemPos(spinner);
            if (index >= allFonts.size() - 1) {
                return;
            }
            String nextFont = allFonts.get(index + 1);
            updateTextTag(spinner, nextFont);
        }
    });
    inflate.findViewById(plusRes).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int index = getItemPos(spinner);
            if (index < 1) {
                return;
            }
            String nextFont = allFonts.get(index - 1);
            updateTextTag(spinner, nextFont);
        }
    });
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) OnClickListener(android.view.View.OnClickListener) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) MenuItem(android.view.MenuItem) TextView(android.widget.TextView) View(android.view.View)

Aggregations

MenuItem (android.view.MenuItem)13 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)13 MyPopupMenu (com.foobnix.pdf.info.view.MyPopupMenu)13 View (android.view.View)5 OnClickListener (android.view.View.OnClickListener)5 TextView (android.widget.TextView)5 AlertDialog (android.app.AlertDialog)4 DialogInterface (android.content.DialogInterface)4 ImageView (android.widget.ImageView)4 MainTabs2 (com.foobnix.ui2.MainTabs2)3 List (java.util.List)3 TargetApi (android.annotation.TargetApi)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 Handler (android.os.Handler)2 OnLongClickListener (android.view.View.OnLongClickListener)2 IntegerResponse (com.foobnix.android.utils.IntegerResponse)2 FileMeta (com.foobnix.dao2.FileMeta)2 CustomSeek (com.foobnix.pdf.info.view.CustomSeek)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1