Search in sources :

Example 1 with HorizontalViewActivity

use of com.foobnix.pdf.search.activity.HorizontalViewActivity in project LibreraReader by foobnix.

the class DragingDialogs method selectTextMenu.

public static DragingPopup selectTextMenu(final FrameLayout anchor, final DocumentController controller, final boolean withAnnotation, final Runnable reloadUI) {
    return new DragingPopup(R.string.text, anchor, 300, 400) {

        @Override
        public View getContentView(LayoutInflater inflater) {
            final View view = inflater.inflate(R.layout.dialog_selected_text, null, false);
            final LinearLayout linearLayoutColor = (LinearLayout) view.findViewById(R.id.colorsLine);
            linearLayoutColor.removeAllViews();
            List<String> colors = new ArrayList<String>(AppState.get().COLORS);
            colors.remove(0);
            colors.remove(0);
            final ImageView underLine = (ImageView) view.findViewById(R.id.onUnderline);
            final ImageView strike = (ImageView) view.findViewById(R.id.onStrike);
            final ImageView selection = (ImageView) view.findViewById(R.id.onSelection);
            final ImageView onAddCustom = (ImageView) view.findViewById(R.id.onAddCustom);
            final LinearLayout customsLayout = (LinearLayout) view.findViewById(R.id.customsLayout);
            final Runnable updateConfigRunnable = new Runnable() {

                @Override
                public void run() {
                    customsLayout.removeAllViews();
                    for (final String line : AppState.get().customConfigColors.split(",")) {
                        if (TxtUtils.isEmpty(line)) {
                            continue;
                        }
                        final ImageView image = new ImageView(controller.getActivity());
                        if (line.startsWith("H")) {
                            image.setImageResource(R.drawable.glyphicons_607_te_background);
                        } else if (line.startsWith("U")) {
                            image.setImageResource(R.drawable.glyphicons_104_te_underline);
                        } else if (line.startsWith("S")) {
                            image.setImageResource(R.drawable.glyphicons_105_te_strike);
                        }
                        String color = line.substring(1);
                        final int colorInt = Color.parseColor(color);
                        TintUtil.setTintImageWithAlpha(image, colorInt);
                        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(Dips.dpToPx(35), Dips.dpToPx(35));
                        int pd = Dips.dpToPx(5);
                        params.leftMargin = pd;
                        image.setPadding(pd, pd, pd, pd);
                        customsLayout.addView(image, params);
                        image.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (line.startsWith("H")) {
                                    controller.underlineText(colorInt, 2.0f, AnnotationType.HIGHLIGHT);
                                } else if (line.startsWith("U")) {
                                    controller.underlineText(colorInt, 2.0f, AnnotationType.UNDERLINE);
                                } else if (line.startsWith("S")) {
                                    controller.underlineText(colorInt, 2.0f, AnnotationType.STRIKEOUT);
                                }
                                closeDialog();
                                controller.saveAnnotationsToFile();
                            }
                        });
                        image.setOnLongClickListener(new OnLongClickListener() {

                            @Override
                            public boolean onLongClick(View v) {
                                AppState.get().customConfigColors = AppState.get().customConfigColors.replace(line, "");
                                customsLayout.removeView(image);
                                return true;
                            }
                        });
                    }
                }
            };
            updateConfigRunnable.run();
            onAddCustom.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PopupMenu menu = new PopupMenu(v.getContext(), v);
                    Drawable highlight = controller.getActivity().getResources().getDrawable(R.drawable.glyphicons_607_te_background);
                    highlight.setColorFilter(Color.parseColor(AppState.get().annotationTextColor), Mode.SRC_ATOP);
                    Drawable underline = controller.getActivity().getResources().getDrawable(R.drawable.glyphicons_104_te_underline);
                    underline.setColorFilter(Color.parseColor(AppState.get().annotationTextColor), Mode.SRC_ATOP);
                    Drawable strikeout = controller.getActivity().getResources().getDrawable(R.drawable.glyphicons_105_te_strike);
                    strikeout.setColorFilter(Color.parseColor(AppState.get().annotationTextColor), Mode.SRC_ATOP);
                    menu.getMenu().add(R.string.highlight_of_text).setIcon(highlight).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().customConfigColors += "H" + AppState.get().annotationTextColor + ",";
                            updateConfigRunnable.run();
                            return false;
                        }
                    });
                    menu.getMenu().add(R.string.underline_of_text).setIcon(underline).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().customConfigColors += "U" + AppState.get().annotationTextColor + ",";
                            updateConfigRunnable.run();
                            return false;
                        }
                    });
                    menu.getMenu().add(R.string.strikethrough_of_text).setIcon(strikeout).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().customConfigColors += "S" + AppState.get().annotationTextColor + ",";
                            updateConfigRunnable.run();
                            return false;
                        }
                    });
                    menu.show();
                    PopupHelper.initIcons(menu, Color.parseColor(AppState.get().annotationTextColor));
                }
            });
            underLine.setColorFilter(Color.parseColor(AppState.get().annotationTextColor));
            strike.setColorFilter(Color.parseColor(AppState.get().annotationTextColor));
            selection.setColorFilter(Color.parseColor(AppState.get().annotationTextColor));
            for (final String colorName : colors) {
                final View inflate = LayoutInflater.from(linearLayoutColor.getContext()).inflate(R.layout.item_color, linearLayoutColor, false);
                inflate.setBackgroundResource(R.drawable.bg_border_2_lines);
                final View img = inflate.findViewById(R.id.itColor);
                final int colorId = Color.parseColor(colorName);
                img.setBackgroundColor(colorId);
                inflate.setTag(colorName);
                linearLayoutColor.addView(inflate);
                inflate.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // Views.unselectChilds(linearLayoutColor);
                        // v.setSelected(true);
                        AppState.get().annotationTextColor = colorName;
                        underLine.setColorFilter(Color.parseColor(colorName));
                        strike.setColorFilter(Color.parseColor(colorName));
                        selection.setColorFilter(Color.parseColor(colorName));
                    }
                });
            }
            final EditText editText = (EditText) view.findViewById(R.id.editText);
            final String selectedText = AppState.get().selectedText;
            // AppState.get().selectedText = null;
            editText.setText(selectedText);
            final View onTranslate = view.findViewById(R.id.onTranslate);
            onTranslate.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    anchor.removeAllViews();
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    final Map<String, String> providers = AppState.getDictionaries(editText.getText().toString().trim());
                    for (final String name : providers.keySet()) {
                        popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                Urls.open(anchor.getContext(), providers.get(name).trim());
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            view.findViewById(R.id.onAddToBookmark).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    ListBoxHelper.showAddDialog(controller, null, null, editText.getText().toString().trim());
                }
            });
            view.findViewById(R.id.readTTS).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    TTSEngine.get().stop();
                    TTSEngine.get().speek(editText.getText().toString().trim());
                }
            });
            view.findViewById(R.id.readTTSNext).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    TTSEngine.get().stop();
                    TTSService.playBookPage(controller.getCurentPageFirst1() - 1, controller.getCurrentBook().getPath(), editText.getText().toString().trim(), controller.getBookWidth(), controller.getBookHeight(), AppState.get().fontSizeSp);
                }
            });
            view.findViewById(R.id.onShare).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    final Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain");
                    String txt = "\"" + editText.getText().toString().trim() + "\" (" + controller.getBookFileMetaName() + ")";
                    intent.putExtra(Intent.EXTRA_TEXT, txt);
                    controller.getActivity().startActivity(Intent.createChooser(intent, controller.getString(R.string.share)));
                }
            });
            view.findViewById(R.id.onCopy).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Context c = anchor.getContext();
                    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                        android.text.ClipboardManager clipboard = (android.text.ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
                        clipboard.setText(editText.getText().toString().trim());
                    } else {
                        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) c.getSystemService(Context.CLIPBOARD_SERVICE);
                        android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", editText.getText().toString().trim());
                        clipboard.setPrimaryClip(clip);
                    }
                    closeDialog();
                }
            });
            view.findViewById(R.id.onGoogle).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    closeDialog();
                    Urls.open(anchor.getContext(), "http://www.google.com/search?q=" + editText.getText().toString().trim());
                }
            });
            TextView onBookSearch = (TextView) view.findViewById(R.id.onBookSearch);
            // onBookSearch.setText(controller.getString(R.string.search_in_the_book)
            // + " \"" + AppState.get().selectedText + "\"");
            onBookSearch.setVisibility(selectedText.contains(" ") ? View.GONE : View.VISIBLE);
            onBookSearch.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchMenu(anchor, controller, selectedText);
                }
            });
            LinearLayout dictLayout = (LinearLayout) view.findViewById(R.id.dictionaryLine);
            dictLayout.removeAllViews();
            final Intent intentProccessText = new Intent();
            if (Build.VERSION.SDK_INT >= 23) {
                intentProccessText.setAction(Intent.ACTION_PROCESS_TEXT);
            }
            intentProccessText.setType("text/plain");
            final Intent intentSearch = new Intent();
            intentSearch.setAction(Intent.ACTION_SEARCH);
            final Intent intentSend = new Intent();
            intentSend.setAction(Intent.ACTION_SEND);
            intentSend.setType("text/plain");
            final Intent intentCustom = new Intent("colordict.intent.action.SEARCH");
            PackageManager pm = anchor.getContext().getPackageManager();
            final List<ResolveInfo> proccessTextList = pm.queryIntentActivities(intentProccessText, 0);
            final List<ResolveInfo> searchList = pm.queryIntentActivities(intentSearch, 0);
            final List<ResolveInfo> sendList = pm.queryIntentActivities(intentSend, 0);
            final List<ResolveInfo> customList = pm.queryIntentActivities(intentCustom, 0);
            final List<ResolveInfo> all = new ArrayList<ResolveInfo>();
            if (Build.VERSION.SDK_INT >= 23) {
                all.addAll(proccessTextList);
            }
            all.addAll(customList);
            all.addAll(searchList);
            all.addAll(sendList);
            final SharedPreferences sp = anchor.getContext().getSharedPreferences("lastDict", Context.MODE_PRIVATE);
            final String lastID = sp.getString("last", "");
            List<String> cache = new ArrayList<String>();
            for (final ResolveInfo app : all) {
                for (final String pkgKey : AppState.appDictionariesKeys) {
                    if (app.activityInfo.packageName.toLowerCase().contains(pkgKey)) {
                        if (cache.contains(app.activityInfo.name)) {
                            continue;
                        }
                        cache.add(app.activityInfo.name);
                        LOG.d("Add APP", app.activityInfo.name);
                        try {
                            ImageView image = new ImageView(anchor.getContext());
                            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(Dips.dpToPx(44), Dips.dpToPx(44));
                            layoutParams.rightMargin = Dips.dpToPx(8);
                            image.setLayoutParams(layoutParams);
                            Drawable icon = anchor.getContext().getPackageManager().getApplicationIcon(app.activityInfo.packageName);
                            image.setImageDrawable(icon);
                            image.setOnClickListener(new OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    String selecteText = editText.getText().toString().trim();
                                    closeDialog();
                                    final ActivityInfo activity = app.activityInfo;
                                    final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
                                    if (customList.contains(app)) {
                                        intentCustom.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentCustom.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentCustom.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                                        intentCustom.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                                        intentCustom.setComponent(name);
                                        intentCustom.putExtra("EXTRA_QUERY", selecteText);
                                        intentCustom.putExtra("EXTRA_HEIGHT", Dips.screenHeight() / 2);
                                        if (AppState.get().isDouble || Dips.screenWidth() > Dips.screenHeight()) {
                                            intentCustom.putExtra("EXTRA_HEIGHT", Dips.screenHeight() * 2 / 3);
                                            if (TempHolder.get().textFromPage == 1) {
                                                intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM | Gravity.RIGHT);
                                            } else if (TempHolder.get().textFromPage == 2) {
                                                intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM | Gravity.LEFT);
                                            } else {
                                                intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM | Gravity.CENTER);
                                            }
                                            intentCustom.putExtra("EXTRA_WIDTH", Dips.screenWidth() / 2);
                                        } else {
                                            intentCustom.putExtra("EXTRA_GRAVITY", Gravity.BOTTOM);
                                        }
                                        controller.getActivity().startActivity(intentCustom);
                                    } else if (proccessTextList.contains(app)) {
                                        intentProccessText.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentProccessText.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentProccessText.setComponent(name);
                                        intentProccessText.putExtra(Intent.EXTRA_TEXT, selecteText);
                                        intentProccessText.putExtra(Intent.EXTRA_PROCESS_TEXT, selecteText);
                                        intentProccessText.putExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, selecteText);
                                        controller.getActivity().startActivity(intentProccessText);
                                    } else if (searchList.contains(app)) {
                                        intentSearch.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentSearch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentSearch.setComponent(name);
                                        intentSearch.putExtra(SearchManager.QUERY, selecteText);
                                        intentSearch.putExtra(Intent.EXTRA_TEXT, selecteText);
                                        controller.getActivity().startActivity(intentSearch);
                                    } else if (sendList.contains(app)) {
                                        intentSend.addCategory(Intent.CATEGORY_LAUNCHER);
                                        intentSend.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
                                        intentSend.setComponent(name);
                                        intentSend.putExtra(Intent.EXTRA_TEXT, selecteText);
                                        controller.getActivity().startActivity(intentSend);
                                    }
                                    sp.edit().putString("last", app.activityInfo.name).commit();
                                }
                            });
                            if (app.activityInfo.name.equals(lastID)) {
                                dictLayout.addView(image, 0);
                            } else {
                                dictLayout.addView(image);
                            }
                        } catch (PackageManager.NameNotFoundException e) {
                            LOG.d(e);
                        }
                    }
                }
            }
            view.findViewById(R.id.onUnderline).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controller.underlineText(Color.parseColor(AppState.get().annotationTextColor), 2.0f, AnnotationType.UNDERLINE);
                    closeDialog();
                    controller.saveAnnotationsToFile();
                }
            });
            view.findViewById(R.id.onStrike).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controller.underlineText(Color.parseColor(AppState.get().annotationTextColor), 2.0f, AnnotationType.STRIKEOUT);
                    closeDialog();
                    controller.saveAnnotationsToFile();
                }
            });
            view.findViewById(R.id.onSelection).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    controller.underlineText(Color.parseColor(AppState.get().annotationTextColor), 2.0f, AnnotationType.HIGHLIGHT);
                    closeDialog();
                    controller.saveAnnotationsToFile();
                }
            });
            if (!BookType.PDF.is(controller.getCurrentBook().getPath()) || !withAnnotation || controller.getActivity() instanceof HorizontalViewActivity || controller.isPasswordProtected()) {
                linearLayoutColor.setVisibility(View.GONE);
                view.findViewById(R.id.onUnderline).setVisibility(View.GONE);
                view.findViewById(R.id.onStrike).setVisibility(View.GONE);
                view.findViewById(R.id.onSelection).setVisibility(View.GONE);
                onAddCustom.setVisibility(View.GONE);
                customsLayout.setVisibility(View.GONE);
            }
            return view;
        }
    }.show("text", true).setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            // controller.clearSelectedText();
            AppState.get().selectedText = null;
        }
    });
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ArrayList(java.util.ArrayList) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) ComponentName(android.content.ComponentName) ImageView(android.widget.ImageView) Context(android.content.Context) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) EditText(android.widget.EditText) Context(android.content.Context) ActivityInfo(android.content.pm.ActivityInfo) AppSharedPreferences(com.foobnix.pdf.info.AppSharedPreferences) SharedPreferences(android.content.SharedPreferences) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) 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) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) LinearLayout(android.widget.LinearLayout) PopupMenu(android.widget.PopupMenu)

Example 2 with HorizontalViewActivity

use of com.foobnix.pdf.search.activity.HorizontalViewActivity in project LibreraReader by foobnix.

the class ExtUtils method openPDFInTextReflow.

public static void openPDFInTextReflow(final Activity a, final File file, final int page, final DocumentController dc) {
    if (ExtUtils.isNotValidFile(file)) {
        Toast.makeText(a, R.string.file_not_found, Toast.LENGTH_SHORT).show();
        return;
    }
    new AsyncTask() {

        AlertDialog dialog;

        Handler handler;

        @Override
        protected void onPreExecute() {
            TempHolder.get().isConverting = true;
            final AlertDialog.Builder builder = new AlertDialog.Builder(a);
            View view = LayoutInflater.from(a).inflate(R.layout.dialog_loading_book, null, false);
            final TextView text = (TextView) view.findViewById(R.id.text1);
            handler = new Handler() {

                @Override
                public void handleMessage(android.os.Message msg) {
                    text.setText(a.getString(R.string.please_wait) + " " + msg.what + "/100%");
                }
            };
            ImageView image = (ImageView) view.findViewById(R.id.onCancel);
            TintUtil.setTintImageWithAlpha(image);
            image.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    LOG.d("loadingBook Cancel");
                    TempHolder.get().isConverting = false;
                    dialog.dismiss();
                }
            });
            builder.setView(view);
            builder.setCancelable(false);
            dialog = builder.show();
            dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }

        @Override
        protected Object doInBackground(Object... params) {
            try {
                return openPDFInTextReflowAsync(a, file, handler);
            } catch (RuntimeException e) {
                LOG.e(e);
                return null;
            }
        }

        @Override
        protected void onPostExecute(final Object result) {
            if (dialog != null) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    LOG.e(e);
                }
            }
            if (!TempHolder.get().isConverting) {
                return;
            }
            if (result != null) {
                Runnable run = new Runnable() {

                    @Override
                    public void run() {
                        if (a instanceof VerticalViewActivity) {
                            AppState.get().isAlwaysOpenAsMagazine = false;
                            AppState.get().isMusicianMode = false;
                            showDocumentWithoutDialog(a, (File) result, page);
                        } else if (a instanceof HorizontalViewActivity) {
                            AppState.get().isAlwaysOpenAsMagazine = true;
                            AppState.get().isMusicianMode = false;
                            showDocumentWithoutDialog(a, (File) result, page);
                        } else {
                            showDocument(a, (File) result);
                        }
                    }
                };
                if (dc != null) {
                    dc.onCloseActivityFinal(run);
                } else {
                    Safe.run(run);
                }
            }
        }
    }.execute();
}
Also used : AlertDialog(android.app.AlertDialog) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) JSONObject(org.json.JSONObject) ImageView(android.widget.ImageView) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) File(java.io.File)

Example 3 with HorizontalViewActivity

use of com.foobnix.pdf.search.activity.HorizontalViewActivity in project LibreraReader by foobnix.

the class ShareDialog method show.

public static void show(final Activity a, final File file, final Runnable onDeleteAction, final int page, final DocumentWrapperUI ui, final DocumentController dc) {
    if (!ExtUtils.isExteralSD(file.getPath()) && ExtUtils.isNotValidFile(file)) {
        Toast.makeText(a, R.string.file_not_found, Toast.LENGTH_LONG).show();
        return;
    }
    final boolean isPDF = BookType.PDF.is(file.getPath());
    // a instanceof MainTabs2 ? false :
    final boolean isLibrary = false;
    // true;
    final boolean isMainTabs = a instanceof MainTabs2;
    List<String> items = new ArrayList<String>();
    if (isLibrary) {
        items.add(a.getString(R.string.library));
    }
    if (dc != null) {
        if (a instanceof VerticalViewActivity || AppState.get().isMusicianMode) {
            items.add(AppState.get().nameHorizontalMode);
        }
        if (a instanceof HorizontalViewActivity || AppState.get().isMusicianMode) {
            items.add(AppState.get().nameVerticalMode);
        }
        if (AppState.get().isMusicianMode == false) {
            items.add(AppState.get().nameMusicianMode);
        }
    }
    if (isPDF) {
        items.add(a.getString(R.string.make_text_reflow));
    }
    items.add(a.getString(R.string.open_with));
    items.add(a.getString(R.string.send_file));
    items.add(a.getString(R.string.export_bookmarks));
    final boolean canDelete = ExtUtils.isExteralSD(file.getPath()) ? true : file.canWrite();
    final boolean isShowInfo = !ExtUtils.isExteralSD(file.getPath());
    if (isMainTabs) {
        if (canDelete) {
            items.add(a.getString(R.string.delete));
        }
        items.add(a.getString(R.string.remove_from_library));
    }
    if (!isMainTabs) {
        items.add(a.getString(R.string.send_snapshot_of_the_page) + " " + (Math.max(page, 0) + 1) + "");
    }
    items.add(a.getString(R.string.tags));
    if (isShowInfo) {
        items.add(a.getString(R.string.file_info));
    }
    final AlertDialog.Builder builder = new AlertDialog.Builder(a);
    // builder.setTitle(R.string.choose_)//
    builder.setItems(items.toArray(new String[items.size()]), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            int i = 0;
            if (isLibrary && which == i++) {
                a.finish();
                MainTabs2.startActivity(a, UITab.getCurrentTabIndex(UITab.SearchFragment));
            }
            if (dc != null && (a instanceof HorizontalViewActivity || AppState.get().isMusicianMode) && which == i++) {
                dc.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        if (AppState.get().isMusicianMode) {
                            AppState.get().isAlwaysOpenAsMagazine = true;
                        } else {
                            AppState.get().isAlwaysOpenAsMagazine = false;
                        }
                        AppState.get().isMusicianMode = false;
                        ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                    }
                });
            }
            if (dc != null && (a instanceof VerticalViewActivity || AppState.get().isMusicianMode) && which == i++) {
                if (dc != null) {
                    dc.onCloseActivityFinal(new Runnable() {

                        @Override
                        public void run() {
                            if (AppState.get().isMusicianMode) {
                                AppState.get().isAlwaysOpenAsMagazine = false;
                            } else {
                                AppState.get().isAlwaysOpenAsMagazine = true;
                            }
                            AppState.get().isMusicianMode = false;
                            ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                        }
                    });
                }
            }
            if (dc != null && AppState.get().isMusicianMode == false && which == i++) {
                dc.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        AppState.get().isMusicianMode = true;
                        AppState.get().isAlwaysOpenAsMagazine = false;
                        ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                    }
                });
            }
            if (isPDF && which == i++) {
                ExtUtils.openPDFInTextReflow(a, file, page + 1, dc);
            }
            if (which == i++) {
                ExtUtils.openWith(a, file);
            } else if (which == i++) {
                ExtUtils.sendFileTo(a, file);
            } else if (which == i++) {
                ExtUtils.sendBookmarksTo(a, file);
            } else if (isMainTabs && canDelete && which == i++) {
                FileInformationDialog.dialogDelete(a, file, onDeleteAction);
            } else if (isMainTabs && which == i++) {
                FileMeta load = AppDB.get().load(file.getPath());
                if (load != null) {
                    load.setIsSearchBook(false);
                    AppDB.get().update(load);
                }
                EventBus.getDefault().post(new UpdateAllFragments());
            } else if (!isMainTabs && which == i++) {
                if (dc != null) {
                    ExtUtils.sharePage(a, file, page, dc.getPageUrl(page).toString());
                } else {
                    ExtUtils.sharePage(a, file, page, null);
                }
            } else if (which == i++) {
                Dialogs.showTagsDialog(a, file, null);
            } else if (isShowInfo && which == i++) {
                FileInformationDialog.showFileInfoDialog(a, file, onDeleteAction);
            }
        }
    });
    AlertDialog create = builder.create();
    create.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.hideNavigation(a);
        }
    });
    create.show();
}
Also used : AlertDialog(android.app.AlertDialog) MainTabs2(com.foobnix.ui2.MainTabs2) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) DialogInterface(android.content.DialogInterface) UpdateAllFragments(com.foobnix.pdf.search.activity.msg.UpdateAllFragments) OnDismissListener(android.content.DialogInterface.OnDismissListener) ArrayList(java.util.ArrayList) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) FileMeta(com.foobnix.dao2.FileMeta)

Aggregations

HorizontalViewActivity (com.foobnix.pdf.search.activity.HorizontalViewActivity)3 AlertDialog (android.app.AlertDialog)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 VerticalViewActivity (org.ebookdroid.ui.viewer.VerticalViewActivity)2 SuppressLint (android.annotation.SuppressLint)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1