Search in sources :

Example 1 with HyphenPattern

use of com.foobnix.hypen.HyphenPattern in project LibreraReader by foobnix.

the class DragingDialogs method moreBookSettings.

public static DragingPopup moreBookSettings(final FrameLayout anchor, final DocumentController controller, final Runnable onRefresh, final Runnable updateUIRefresh) {
    final int initCssHash = BookCSS.get().toCssString().hashCode();
    DragingPopup dialog = new DragingPopup(R.string.reading_settings, anchor, PREF_WIDTH, PREF_HEIGHT) {

        @Override
        public void beforeCreate() {
            titleAction = controller.getString(R.string.preferences);
            titleRunnable = new Runnable() {

                @Override
                public void run() {
                    if (initCssHash != BookCSS.get().toCssString().hashCode()) {
                        AlertDialogs.showDialog(controller.getActivity(), controller.getString(R.string.you_neet_to_apply_the_new_settings), controller.getString(R.string.apply), new Runnable() {

                            @Override
                            public void run() {
                                closeDialog();
                            }
                        });
                    } else {
                        preferences(anchor, controller, onRefresh, updateUIRefresh);
                    }
                }
            };
        }

        @Override
        public View getContentView(final LayoutInflater inflater) {
            View inflate = inflater.inflate(R.layout.dialog_reading_pref, null, false);
            final CustomSeek fontWeight = (CustomSeek) inflate.findViewById(R.id.fontWeight);
            fontWeight.init(1, 9, BookCSS.get().fontWeight / 100);
            fontWeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    fontWeight.setValueText("" + (result * 100));
                    BookCSS.get().fontWeight = result * 100;
                    return false;
                }
            });
            fontWeight.setValueText("" + BookCSS.get().fontWeight);
            // begin styles
            final List<String> docStyles = // 
            Arrays.asList(// 
            controller.getString(R.string.document_styles) + " + " + controller.getString(R.string.user_styles), // 
            controller.getString(R.string.document_styles), controller.getString(R.string.user_styles));
            final TextView docStyle = (TextView) inflate.findViewById(R.id.documentStyle);
            docStyle.setText(docStyles.get(BookCSS.get().documentStyle));
            TxtUtils.underlineTextView(docStyle);
            inflate.findViewById(R.id.documentStyleLayout).setVisibility(ExtUtils.isTextFomat(controller.getCurrentBook().getPath()) ? View.VISIBLE : View.GONE);
            docStyle.setOnClickListener(new OnClickListener() {

                @SuppressLint("NewApi")
                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (int i = 0; i < docStyles.size(); i++) {
                        String type = docStyles.get(i);
                        final int j = i;
                        popupMenu.getMenu().add(type).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().documentStyle = j;
                                docStyle.setText(docStyles.get(BookCSS.get().documentStyle));
                                TxtUtils.underlineTextView(docStyle);
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // end styles
            // hypens
            boolean isSupportHypens = controller.isTextFormat();
            CheckBox isAutoHypens = (CheckBox) inflate.findViewById(R.id.isAutoHypens);
            isAutoHypens.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
            isAutoHypens.setChecked(BookCSS.get().isAutoHypens);
            isAutoHypens.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    BookCSS.get().isAutoHypens = isChecked;
                }
            });
            final TextView hypenLangLabel = (TextView) inflate.findViewById(R.id.hypenLangLabel);
            final TextView hypenLang = (TextView) inflate.findViewById(R.id.hypenLang);
            hypenLang.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
            hypenLangLabel.setVisibility(isSupportHypens ? View.VISIBLE : View.GONE);
            // hypenLang.setVisibility(View.GONE);
            // hypenLangLabel.setVisibility(View.GONE);
            hypenLang.setText(DialogTranslateFromTo.getLanuageByCode(BookCSS.get().hypenLang));
            TxtUtils.underlineTextView(hypenLang);
            hypenLang.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    HyphenPattern[] values = HyphenPattern.values();
                    List<String> all = new ArrayList<String>();
                    for (HyphenPattern p : values) {
                        String e = DialogTranslateFromTo.getLanuageByCode(p.lang) + ":" + p.lang;
                        all.add(e);
                    }
                    Collections.sort(all);
                    for (final String langFull : all) {
                        String[] split = langFull.split(":");
                        final String titleLang = split[0];
                        final String code = split[1];
                        popupMenu.getMenu().add(titleLang).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().hypenLang = code;
                                hypenLang.setText(titleLang);
                                TxtUtils.underlineTextView(hypenLang);
                                FileMeta load = AppDB.get().load(controller.getCurrentBook().getPath());
                                if (load != null) {
                                    load.setLang(code);
                                    AppDB.get().update(load);
                                }
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // - hypens
            View customCSS = inflate.findViewById(R.id.customCSS);
            // TxtUtils.underlineTextView(customCSS);
            customCSS.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(final View v) {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
                    builder.setTitle(R.string.custom_css);
                    final EditText edit = new EditText(v.getContext());
                    edit.setMinWidth(Dips.dpToPx(1000));
                    edit.setLines(8);
                    edit.setGravity(Gravity.TOP);
                    edit.setText(BookCSS.get().customCSS1);
                    builder.setView(edit);
                    builder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(final DialogInterface dialog, final int id) {
                            BookCSS.get().customCSS1 = edit.getText().toString();
                            BookCSS.get().save(v.getContext());
                        }
                    });
                    builder.show();
                }
            });
            final CustomSeek lineHeight = (CustomSeek) inflate.findViewById(R.id.lineHeight);
            lineHeight.init(0, 30, BookCSS.get().lineHeight);
            lineHeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().lineHeight = result;
                    return false;
                }
            });
            final CustomSeek paragraphHeight = (CustomSeek) inflate.findViewById(R.id.paragraphHeight);
            paragraphHeight.init(0, 20, BookCSS.get().paragraphHeight);
            paragraphHeight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().paragraphHeight = result;
                    return false;
                }
            });
            final CustomSeek fontParagraph = (CustomSeek) inflate.findViewById(R.id.fontParagraph);
            fontParagraph.init(0, 30, BookCSS.get().textIndent);
            fontParagraph.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().textIndent = result;
                    return false;
                }
            });
            final CustomSeek emptyLine = (CustomSeek) inflate.findViewById(R.id.emptyLine);
            // || //
            boolean isShow = BookType.FB2.is(controller.getCurrentBook().getPath());
            // BookType.HTML.is(controller.getCurrentBook().getPath()) || //
            // BookType.TXT.is(controller.getCurrentBook().getPath());//
            emptyLine.setVisibility(isShow ? View.VISIBLE : View.GONE);
            emptyLine.init(0, 30, BookCSS.get().emptyLine);
            emptyLine.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().emptyLine = result;
                    return false;
                }
            });
            // Margins
            final CustomSeek marginTop = (CustomSeek) inflate.findViewById(R.id.marginTop);
            marginTop.init(0, 30, BookCSS.get().marginTop);
            marginTop.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginTop = result;
                    return false;
                }
            });
            final CustomSeek marginBottom = (CustomSeek) inflate.findViewById(R.id.marginBottom);
            marginBottom.init(0, 30, BookCSS.get().marginBottom);
            marginBottom.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginBottom = result;
                    return false;
                }
            });
            final CustomSeek marginLeft = (CustomSeek) inflate.findViewById(R.id.marginLeft);
            marginLeft.init(0, 30, BookCSS.get().marginLeft);
            marginLeft.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginLeft = result;
                    return false;
                }
            });
            final CustomSeek marginRight = (CustomSeek) inflate.findViewById(R.id.marginRight);
            marginRight.init(0, 30, BookCSS.get().marginRight);
            marginRight.setOnSeekChanged(new IntegerResponse() {

                @Override
                public boolean onResultRecive(int result) {
                    BookCSS.get().marginRight = result;
                    return false;
                }
            });
            // font folder
            LOG.d("fontFolder2-2", BookCSS.get().fontFolder);
            final TextView fontsFolder = (TextView) inflate.findViewById(R.id.fontsFolder);
            TxtUtils.underline(fontsFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
            fontsFolder.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    ChooserDialogFragment.chooseFolder((FragmentActivity) controller.getActivity(), BookCSS.get().fontFolder).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                        @Override
                        public boolean onResultRecive(String nPath, Dialog dialog) {
                            File result = new File(nPath);
                            BookCSS.get().fontFolder = result.getPath();
                            TxtUtils.underline(fontsFolder, TxtUtils.lastTwoPath(BookCSS.get().fontFolder));
                            BookCSS.get().save(controller.getActivity());
                            dialog.dismiss();
                            return false;
                        }
                    });
                }
            });
            final View downloadFonts = inflate.findViewById(R.id.downloadFonts);
            downloadFonts.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    FontExtractor.showDownloadFontsDialog(controller.getActivity(), downloadFonts, fontsFolder);
                }
            });
            // / aling
            final Map<Integer, String> alignConst = new LinkedHashMap<Integer, String>();
            alignConst.put(BookCSS.TEXT_ALIGN_JUSTIFY, controller.getString(R.string.width));
            alignConst.put(BookCSS.TEXT_ALIGN_LEFT, controller.getString(R.string.left));
            alignConst.put(BookCSS.TEXT_ALIGN_RIGHT, controller.getString(R.string.right));
            alignConst.put(BookCSS.TEXT_ALIGN_CENTER, controller.getString(R.string.center));
            // align
            final TextView textAlign = (TextView) inflate.findViewById(R.id.textAlign);
            textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
            textAlign.setOnClickListener(new OnClickListener() {

                @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                @Override
                public void onClick(View v) {
                    if (Build.VERSION.SDK_INT <= 10) {
                        BookCSS.get().textAlign += 1;
                        if (BookCSS.get().textAlign == 4) {
                            BookCSS.get().textAlign = 0;
                        }
                        textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
                        return;
                    }
                    final PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
                    for (final int key : alignConst.keySet()) {
                        String name = alignConst.get(key);
                        popupMenu.getMenu().add(name).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                            @Override
                            public boolean onMenuItemClick(MenuItem item) {
                                BookCSS.get().textAlign = key;
                                textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
                                return false;
                            }
                        });
                    }
                    popupMenu.show();
                }
            });
            // link color
            final CustomColorView linkColorDay = (CustomColorView) inflate.findViewById(R.id.linkColorDay);
            linkColorDay.withDefaultColors(Color.parseColor(BookCSS.LINK_COLOR_DAY), Color.parseColor(BookCSS.LINK_COLOR_UNIVERSAL));
            linkColorDay.init(Color.parseColor(BookCSS.get().linkColorDay));
            linkColorDay.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    BookCSS.get().linkColorDay = string;
                    return false;
                }
            });
            final CustomColorView linkColorNight = (CustomColorView) inflate.findViewById(R.id.linkColorNight);
            linkColorNight.withDefaultColors(Color.parseColor(BookCSS.LINK_COLOR_NIGHT), Color.parseColor(BookCSS.LINK_COLOR_UNIVERSAL));
            linkColorNight.init(Color.parseColor(BookCSS.get().linkColorNight));
            linkColorNight.setOnColorChanged(new StringResponse() {

                @Override
                public boolean onResultRecive(String string) {
                    BookCSS.get().linkColorNight = string;
                    return false;
                }
            });
            linkColorDay.getText1().getLayoutParams().width = Dips.dpToPx(150);
            linkColorNight.getText1().getLayoutParams().width = Dips.dpToPx(150);
            TxtUtils.underlineTextView((TextView) inflate.findViewById(R.id.onResetStyles)).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    AlertDialogs.showOkDialog(controller.getActivity(), controller.getString(R.string.restore_defaults_full), new Runnable() {

                        @Override
                        public void run() {
                            BookCSS.get().resetToDefault(controller.getActivity());
                            fontsFolder.setText(TxtUtils.underline(TxtUtils.lastTwoPath(BookCSS.get().fontFolder)));
                            textAlign.setText(TxtUtils.underline(alignConst.get(BookCSS.get().textAlign)));
                            fontWeight.reset(BookCSS.get().fontWeight / 100);
                            fontWeight.setValueText("" + BookCSS.get().fontWeight);
                            lineHeight.reset(BookCSS.get().lineHeight);
                            paragraphHeight.reset(BookCSS.get().paragraphHeight);
                            fontParagraph.reset(BookCSS.get().textIndent);
                            // 
                            marginTop.reset(BookCSS.get().marginTop);
                            marginBottom.reset(BookCSS.get().marginBottom);
                            marginLeft.reset(BookCSS.get().marginLeft);
                            marginRight.reset(BookCSS.get().marginRight);
                            emptyLine.reset(BookCSS.get().emptyLine);
                            linkColorDay.init(Color.parseColor(BookCSS.get().linkColorDay));
                            linkColorNight.init(Color.parseColor(BookCSS.get().linkColorNight));
                        }
                    });
                }
            });
            return inflate;
        }
    };
    dialog.show(DragingPopup.PREF + "_moreBookSettings");
    dialog.setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            if (initCssHash != BookCSS.get().toCssString().hashCode()) {
                AppState.get().save(controller.getActivity());
                if (onRefresh != null) {
                    onRefresh.run();
                }
                controller.restartActivity();
            }
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) StringResponse(com.foobnix.StringResponse) LinkedHashMap(java.util.LinkedHashMap) Dialog(android.app.Dialog) ProgressDialog(android.app.ProgressDialog) ColorsDialog(com.foobnix.pdf.info.widget.ColorsDialog) AlertDialog(android.app.AlertDialog) FontDialog(com.foobnix.pdf.info.widget.FontDialog) TapZoneDialog(com.foobnix.pdf.info.widget.TapZoneDialog) HyphenPattern(com.foobnix.hypen.HyphenPattern) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) EditText(android.widget.EditText) ResultResponse2(com.foobnix.android.utils.ResultResponse2) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) IntegerResponse(com.foobnix.android.utils.IntegerResponse) MenuItem(android.view.MenuItem) 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) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) SuppressLint(android.annotation.SuppressLint) File(java.io.File) TargetApi(android.annotation.TargetApi) CompoundButton(android.widget.CompoundButton) FileMeta(com.foobnix.dao2.FileMeta) PopupMenu(android.widget.PopupMenu)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 OnMenuItemClickListener (android.view.MenuItem.OnMenuItemClickListener)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 EditText (android.widget.EditText)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1